{"id":2845,"date":"2018-03-05T19:56:16","date_gmt":"2018-03-05T10:56:16","guid":{"rendered":"http:\/\/taitan916.info\/blog\/?p=2845"},"modified":"2024-01-13T00:41:10","modified_gmt":"2024-01-12T15:41:10","slug":"post-2845","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/2845","title":{"rendered":"Google Maps API\u3067\u8907\u6570\u306e\u30de\u30fc\u30ab\u30fc\u3092\u307e\u3068\u3081\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Google Maps API\u3067\u30de\u30fc\u30ab\u30fc\u3092\u8907\u6570\u8868\u793a\u3057\u3001\u8fd1\u96a3\u306e\u30a8\u30ea\u30a2\u3054\u3068\u306b\u307e\u3068\u3081\u3066\u8868\u793a\u3055\u305b\u305f\u304b\u3063\u305f\u3002\u8abf\u3079\u305f\u3068\u3053\u308dGoogle\u516c\u5f0f\u3067API\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u305f\u3002\u4ee5\u4e0b\u306b\u4f5c\u6210\u65b9\u6cd5\u306e\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p><a href=\"https:\/\/taitan916.info\/sample\/clusterer\/\" target=\"_blank\" rel=\"noopener\">https:\/\/taitan916.info\/sample\/clusterer\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e8b\u524d\u6e96\u5099<\/h2>\n<p>\u30de\u30fc\u30ab\u30fc\u306e\u8868\u793a\u3068\u81ea\u52d5\u30ba\u30fc\u30e0\u304c\u5165\u3063\u305f\u30de\u30c3\u30d7\u306e\u4f5c\u6210\u306b\u95a2\u3057\u3066\u306f\u4ee5\u524d\u306e\u8a18\u4e8b\u306e\u3082\u306e\u3092\u4f7f\u7528\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/taitan916.info\/blog\/?p=2403\" target=\"_blank\" rel=\"noopener\">http:\/\/taitan916.info\/blog\/?p=2403<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f<\/h2>\n<p>\u4ee5\u4e0b\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304a\u304f\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;script src=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/examples\/markerclusterer\/markerclusterer.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>JavaScript\u90e8\u5206<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;script&gt;\r\nvar mapData = [\r\n    { 'name':'\u5927\u962a\u57ce', 'x':'34.687315', 'y':'135.526201'}, \r\n    { 'name':'\u901a\u5929\u95a3', 'x':'34.644885', 'y':'135.494516'}, \r\n    { 'name':'\u9053\u9813\u5800', 'x':'34.668548', 'y':'135.502715'}, \r\n    { 'name':'\u4eac\u90fd\u30bf\u30ef\u30fc', 'x':'34.987574', 'y':'135.759362'}, \r\n];\r\nvar minLat = 999;\r\nvar maxLat = 0;\r\nvar minLng = 999;\r\nvar maxLng = 0;\r\n\r\nvar currentWindow = null;\r\n\r\nvar latlng = new google.maps.LatLng(mapData[0].x, mapData[0].y);\r\nvar myOptions = {\r\n    center: latlng, \r\n    mapTypeId: google.maps.MapTypeId.ROADMAP\r\n};\r\n\r\nvar map = new google.maps.Map(document.getElementById(\"map_canvas\"), myOptions);\r\n\r\n\/\/\u30de\u30fc\u30ab\u30fc\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u7528\u306e\u914d\u5217\r\nvar clusterer = [];\r\n\r\nfor (var key in mapData){\r\n    var marker_data = makeMarker(mapData[key]);\r\n    \/\/\u30de\u30fc\u30ab\u30fc\u60c5\u5831\u3092\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0\u7528\u306e\u914d\u5217\u306b\u7a81\u3063\u8fbc\u3080\r\n    clusterer.push(marker_data);\r\n}\r\n\r\n\/\/\u30de\u30c3\u30d7\u306b\u30de\u30fc\u30ab\u30fc\u30af\u30e9\u30b9\u30bf\u30fc\u3092\u8ffd\u52a0\r\nvar markerCluster = new MarkerClusterer(map, clusterer, {imagePath: 'https:\/\/developers.google.com\/maps\/documentation\/javascript\/examples\/markerclusterer\/m'});\r\n\r\nautoZoom( maxLat, minLat, maxLng, minLng );\r\n\r\nfunction makeMarker( mapData ){\r\n    if( !mapData ) return false;\r\n\r\n    if(mapData.x &lt; minLat) minLat = mapData.x;\r\n    if(mapData.x &gt; maxLat) maxLat = mapData.x;\r\n    if(mapData.y &lt; minLng) minLng = mapData.y;\r\n    if(mapData.y &gt; maxLng) maxLng = mapData.y;\r\n\r\n    var marker = new google.maps.Marker({\r\n        position : new google.maps.LatLng(mapData.x,mapData.y), \r\n        map: map \r\n    });\r\n\r\n    var infoWindow = new google.maps.InfoWindow();\r\n    google.maps.event.addListener(marker, 'click', function() {\r\n        if( currentWindow ) currentWindow.close();\r\n\r\n        infoWindow.setContent(mapData.name);\r\n        infoWindow.open(map,marker);\r\n        currentWindow = infoWindow;\r\n    });\r\n    return marker;\r\n}\r\n\r\nfunction autoZoom( maxLat, minLat, maxLng, minLng ){\r\n    if( !maxLat || !minLat || !maxLng || !minLng ) return false;\r\n\r\n    var sw = new google.maps.LatLng(maxLat,minLng);\r\n    var ne = new google.maps.LatLng(minLat,maxLng);\r\n    var bounds = new google.maps.LatLngBounds(sw, ne);\r\n    map.fitBounds(bounds);\r\n}\r\n\r\n&lt;\/script&gt;<\/pre>\n<p>\u30b3\u30e1\u30f3\u30c8\u3092\u5165\u308c\u3066\u3042\u308b\u90e8\u5206\u304c\u4ee5\u524d\u306e\u8a18\u4e8b\u306e\u30bd\u30fc\u30b9\u3068\u306f\u7570\u306a\u308b\u90e8\u5206\u306b\u306a\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<p><a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/marker-clustering?hl=ja\" target=\"_blank\" rel=\"noopener\">https:\/\/developers.google.com\/maps\/documentation\/javascript\/marker-clustering?hl=ja<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Maps API\u3067\u30de\u30fc\u30ab\u30fc\u3092\u8907\u6570\u8868\u793a\u3057\u3001\u8fd1\u96a3\u306e\u30a8\u30ea\u30a2\u3054\u3068\u306b\u307e\u3068\u3081\u3066 ... <\/p>\n","protected":false},"author":1,"featured_media":1423,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[71,70],"tags":[],"class_list":["post-2845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google-maps-api","category-google"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/2845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=2845"}],"version-history":[{"count":0,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/2845\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1423"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=2845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=2845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=2845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}