【发布时间】:2014-01-01 18:55:50
【问题描述】:
您能否查看this Link 并告诉我为什么我无法从地图中删除标记?我收到此错误消息:
Uncaught TypeError: Object [object Array] has no method 'setMap'
代码:
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
$( "#trg" ).click(function() {
$.ajax({
// type: "POST",
url: 'SO_20131215_data.json.txt',
dataType: 'json',
success: function(data){
locations.length = 0;
for (p = 0; p < data.markers.length; p++) {
locations.push(Array(data.markers[p].latitude,data.markers[p].longitude));
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.markers[p].latitude,data.markers[p].longitude),
map: map,
title:"marker "+p
});
}
},
error: function (xhr,status,errorStr) {
alert("status="+status+", error="+errorStr);
}
});
});
function removeMarkers() {
for (i = 0; i < locations.length; i++) {
locations[i].setMap(null)
}
}
$('#remover').click(function () {
removeMarkers();
});
【问题讨论】:
标签: google-maps google-maps-api-3 google-maps-markers