Last active
August 29, 2015 14:27
-
-
Save nekoneko-wanwan/8a36a8b8b6b988ba1a09 to your computer and use it in GitHub Desktop.
Google MapとMarker clusterの連動基本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 省略 --> | |
<script src="https://maps.googleapis.com/maps/api/js"></script> | |
<script src="markerclusterer_compiled.js"></script> | |
<script src="map.js"></script> | |
<!-- 省略 --> | |
<!-- | |
markerclusterer_compiled.js | |
src -> https://github.com/googlemaps/js-marker-clusterer | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mapCanvas = document.getElementById('map'); | |
var mapOptions = { | |
center: new google.maps.LatLng(緯度,経度) | |
}; | |
var myMap = new google.maps.Map(mapCanvas, mapOptions); | |
var markers = [], marker, markerOptions; | |
var ary = []; // 緯度経度の入った配列データを用意する | |
var i = 0; | |
var l = ary.length; | |
for (; i < l; i++) { | |
markerOptions = { | |
position: new google.maps.LatLng(ary[i][1], ary[i][0]) | |
}; | |
marker = new google.maps.Marker(markerOptions); | |
markers.push(marker); | |
} | |
var markerCluster = new MarkerClusterer(myMap, markers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment