我使用Google Maps API并在地图上添加标记:
for(var i = 1; i <= 100; i++){
var position = {lat : i, lng : i};
var marker = new google.maps.Marker({
position: position,
map: map,
draggable: true
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
如果之前创建了此标记,我如何更新marker[i] = 22
的坐标?
答案 0 :(得分:0)
将标记放入数组并使用setPosition
var markers;
var k;
for(var i = 1; i <= 100; i++){
var position = {lat : i, lng : i};
var marker = new google.maps.Marker({
position: position,
map: map,
draggable: true
});
k = markers.push(marker);
markers[k-1].addListener('click', function() {
infowindow.open(map, this);
});
}
.....
var myNewlatlng = new google.maps.LatLng( 24.397, 40.644);
markers[22] setPosition(myNewlatlng);