简体   繁体   中英

Hide marker in google map at zoom level 3

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?

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);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM