问题
How to hide marker in a google map in zoom level 3, and while zooming in (for upto 16th level) I have to show the marker again. I am using Google Maps JavaScript API v3.
Note: There is only one marker in the map.
Can any one help me to get this done?
回答1:
You will have to add an zoom_changed
event to the map, and check which zoomlevel your map is and act accordingly. See also the API Reference: Map Events and Overlays.
Partial code (you might want to update / add something here and there):
var marker = new google.maps.Marker({
position: location,
map: map
});
google.maps.event.addListener(map, 'zoom_changed', function() {
var zoom = map.getZoom();
// Update May 2017
// You can now use setVisible() on a marker instead of
// setting the map to a null value.
if (zoom <= 3) {
marker.setMap(null);
} else {
marker.setMap(map);
}
});
来源:https://stackoverflow.com/questions/10446335/hide-marker-in-google-map-at-zoom-level-3