var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: tittle,
zIndex: i,
draggable: true
});
google.maps.event.addListener(marker, 'drag', function() {
$("input[name='request']").val(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function() {
$("input[name='request']").val(marker.getPosition());
});
事件被添加到单个标记中,需要至少1000或甚至无限。
答案 0 :(得分:1)
使用位置数组,并为每个位置调用addMarker方法。
var locationsArray;
for(var i = 0 ; i<locationsArray.length; i++){
addMarker(locationsArray[i]);
}
function addMarker(myLatLng){
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: tittle,
zIndex: i,
draggable: true
});
google.maps.event.addListener(marker, 'drag', function() {
$("input[name='request']").val(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function() {
$("input[name='request']").val(marker.getPosition());
});
}