如何在Google地图中添加多个标记?

时间:2010-02-26 06:03:44

标签: google-maps

我在Google地图和Bing地图上工作,想要在地图上添加多个标记(叠加)来自某些地方,我不知道如何使用此API添加。

1 个答案:

答案 0 :(得分:3)

 function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);

        // Add 10 markers to the map at random locations
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        for (var i = 0; i < 10; i++) {
          var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
                                  southWest.lng() + lngSpan * Math.random());
          map.addOverlay(new GMarker(latlng));
        }
      }
    }

不要忘记包含javascript文件。更多细节here

来源:http://code.google.com/apis/maps/documentation/examples/marker-simple.html