0
我在Google地图和Bing地图上工作,并希望在地图上添加多个标记(叠加层)。我从某些地方获得了GMap.js,并且我不知道如何使用此API添加。如何在Google Map中添加多个标记?
我在Google地图和Bing地图上工作,并希望在地图上添加多个标记(叠加层)。我从某些地方获得了GMap.js,并且我不知道如何使用此API添加。如何在Google Map中添加多个标记?
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