我需要在Maps API v3
中的多个标记周围放置圆圈这是我到目前为止所做的:
function initialize(){
var locations = [
['Band Stand', 19.04519, 72.819091],
['Gateway Of India Mumbai', 18.921984, 72.834654],
['Haji Ali', 18.9778192, 72.8104819],
['Kings Circle', 19.032261, 72.857225],
];
var map = new google.maps.Map(document.getElementById('map-sec'), {
zoom: 12,
center: new google.maps.LatLng(19.0822507,72.8811862),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var circle = new google.maps.Circle({
map: map,
radius: 1000,
fillColor: '#AA0000'
});
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
circle.bindTo('center', marker, 'position');
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
google.maps.event.addDomListener(window, 'load', initialize);
然而,这只是围绕其中一个位置给我一个圆圈。如何获得多个圈子?
答案 0 :(得分:2)
尝试移动它:
var circle = new google.maps.Circle({
map: map,
radius: 1000,
fillColor: '#AA0000'
});
..在for循环中:
for (i = 0; i < locations.length; i++) {
var circle = new google.maps.Circle({
map: map,
radius: 1000,
fillColor: '#AA0000'
});
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
circle.bindTo('center', marker, 'position');
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}