Skip to content

Instantly share code, notes, and snippets.

@nekoneko-wanwan
Last active August 29, 2015 14:27
Show Gist options
  • Save nekoneko-wanwan/8a36a8b8b6b988ba1a09 to your computer and use it in GitHub Desktop.
Save nekoneko-wanwan/8a36a8b8b6b988ba1a09 to your computer and use it in GitHub Desktop.
Google MapとMarker clusterの連動基本
<!-- 省略 -->
<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
-->
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