1

我是谷歌地图的新手。我已经阅读了Overlapping Marker Spiderfier文档,但我仍然对如何在我的地图中实现它感到困惑。

这是我的尝试:

function initialize() {
    var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 7,
        center: new google.maps.LatLng(40.0000, 48.0000),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDefaultUI: true,
        zoomControl: true
    });
    var locations = [[40.0000, 48.0000], [40.0000, 48.0000], [40.0000, 48.0000]];
    var marker, i;
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][0], locations[i][1]),
            map: map
        });
    }
}
google.maps.event.addDomListener(window, 'load', initialize);

您可以在jsfiddle中找到此代码。

4

1 回答 1

5

这是您的代码更新...

function initialize() {

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: new google.maps.LatLng(40.0000, 48.0000),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI: true,
      zoomControl: true
    });
    var locations =[ [40.0000, 48.0000],[40.0000, 48.0000],[40.0000, 48.0000]];

    oms = new OverlappingMarkerSpiderfier(map,
        {markersWontMove: true, markersWontHide: true, keepSpiderfied: true, circleSpiralSwitchover: 40 });

    var marker, i;
      for (i = 0; i < locations.length; i++) {  
         marker = new google.maps.Marker({
           position: new google.maps.LatLng(locations[i][0], locations[i][1]),
           map: map
         });
         oms.addMarker(marker);
      }
}
google.maps.event.addDomListener(window, 'load', initialize);
于 2013-07-29T17:47:34.217 回答