Is it OK? clearOverlays() in GMap API V2 to Google Maps API V3?
I use Google Maps API V3.
I migrate My site GMap API V2 -> V3. but coped because I used the clearOverlays() method to delete an existing object at once in the V2 , and it deleted an object in what had been abolished in V3 individually.
V2
map.clearOverlays();
V3
map.set_visible(false);
popup.close();
is it OK? or other solutions?
I couldn't find anything in the V3 reference which will explicitly clear the overlays created on the map and I could't find any code samples which do this either.
I think that it is important to point out the V3 API is a very early developer release and contains only a very basic set of features. It is quite possible that they simply haven't got to this functionality yet. If you are working on a live system, I suggest you stick with V2 until V3 is more mature.
There is a post on the developer group which asks the question about how the API should be used with a very useful answer from the V3 product manager:
Misconception about v3 Options
EDIT:
OK, it seems like this functionality is missing from the API deliberately in order to keep it lightweight. You should keep track of your overlay objects yourself and call:
object.set_map(null);
to remove them.
Here is what I do:
create an empty array literal, push the markers as you make them, and then evict them when necessary
var eviction_list = [];
function evictMarkers() {
// clear all markers
$(eviction_list).each(function () {
this.set_map(null);
});
// reset the eviction array
eviction_list = [];
}
//in function adding markers
......
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: elem.title
});
eviction_list.push(marker);
......
//to clear all markers
evictMarkers();
As hongwei correctly mentions, the function is called setMap(), not set_map().
See http://code.google.com/apis/maps/documentation/v3/overlays.html#HideShow
链接地址: http://www.djcxy.com/p/81494.html上一篇: 计算谷歌地图V3中两点之间的距离