【发布时间】:2013-11-15 02:56:57
【问题描述】:
我正在添加这样的制造商:
var markers = [];
var map = null;
$.ajax({
type:"GET",
dataType:"json",
url:"<?php echo site_url("sandbox_faizan/get_coordinates") ?>",
success: function(result)
{
for(var i=0;i<result.length;i++)
{
var obj = [] ;
obj.lat=result[i].lat;
obj.lng=result[i].lng;
obj.count=result[i].Count;
// points.push(new google.maps.LatLng(result[i].lat,result[i].lng));
markers.push(obj);
//console.log(points[i]);
console.log(markers[i]);
}
addMarkers();
}
});
function addMarkers() {
// when the map is initialized and the points have been initialized, add them to the map
if ((map != null) && (markers.length > 0)) {
for (var i = 0; i < markers.length; i++) {
var marker = new MarkerWithLabel({
map: map,
position: new google.maps.LatLng(markers[i].lat,markers[i].lng),
icon: pinImage,
shadow: pinShadow,
labelContent: markers[i].count,
labelAnchor: new google.maps.Point(12, -5),
labelClass: "labels"
});
bounds.extend (new google.maps.LatLng(markers[i].lat,markers[i].lng));
map.fitBounds (bounds);
}
}
}
我正在清除这样的标记:
function remove_markers(){
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i < this.markers.length; i++){
this.markers[i].setMap(null);
alert("removing now"); // THIS DOES NOT ALERT
}
this.markers = new Array();
};
}
它什么也没做,我尝试了其他使用 setMap(null) 的方法,之前它给了我错误未捕获的类型错误 setMap not defined in console。
我做错了什么?
【问题讨论】:
-
控制台不记录任何内容?
-
这种情况下什么都没有,连alert都不弹出来。
标签: javascript google-maps google-maps-api-3 google-maps-markers removeall