在谷歌地图API v2中,如果我想删除所有的地图标记,我可以简单地做到。
map.clearOverlays();
在谷歌地图API v3中,我如何做到这一点呢?
看了一下参考API,我不清楚。
似乎V3中还没有这样的功能。
人们建议在一个数组中保留对地图上所有标记物的引用。然后,当你想把它们全部删除时,只需在数组中进行循环,并对每个引用调用.setMap(null)方法。
更多信息/代码见本问题 。
我的版本。
google.maps.Map.prototype.markers = new Array(); google.maps.Map.prototype.getMarkers = function() { return this.markers }; google.maps.Map.prototype.clearMarkers = function() { for(var i=0; i
google.maps.Map.prototype.markers = new Array(); google.maps.Map.prototype.addMarker = function(marker) { this.markers[this.markers.length] = marker; }; google.maps.Map.prototype.getMarkers = function() { return this.markers }; google.maps.Map.prototype.clearMarkers = function() { for(var i=0; i
两个答案中发布的"set_map"函数似乎在Google Maps v3 API中不再工作。
set_map
我想知道发生了什么
更新:
谷歌似乎改变了他们的API,使"set_map"不是"setMap"。
setMap
http://code.google.com/apis/maps/documentation/v3/reference.html
似乎V3中还没有这样的功能。
人们建议在一个数组中保留对地图上所有标记物的引用。然后,当你想把它们全部删除时,只需在数组中进行循环,并对每个引用调用.setMap(null)方法。
更多信息/代码见本问题 。
我的版本。
两个答案中发布的"
set_map
"函数似乎在Google Maps v3 API中不再工作。我想知道发生了什么
更新:
谷歌似乎改变了他们的API,使"
set_map
"不是"setMap
"。http://code.google.com/apis/maps/documentation/v3/reference.html