Hide marker in google map at zoom level 3

徘徊边缘 提交于 2021-01-29 04:20:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!