标记可见性在Google地图中

问题描述:

我正在构建一个寻宝者应用程序,我需要能够隐藏标记,并且只能在某个缩放级别显示。

I'm building a treasure hunter app and I need to be able to hide a marker and only make it visible at a certain zoom level.

我如何实现这一点?

我正在使用自定义标记和谷歌地图v3。

I'm using a custom marker and google maps v3.

谢谢。

哦,有什么奇怪的是,我可以在某个缩放级别关闭能见度,如下面的代码所示:

Oh and what's weird is that I can turn the visibility off at a certain zoom level like in the following code:

var marker = new google.maps.Marker({
    draggable: false,
    raiseOnDrag: false,
    clickable: true,
    icon: image,
    shadow: shadow,
    shape: shape,
    map: map,
    url: 'http://www.google.com/',
    visible: true,
    position: markerLatlng
});

var zoomLevel;
//marker.visible = false;

google.maps.event.addListener(marker, 'click', function() {
    window.location.href = marker.url;
});

var infowindow = new google.maps.InfoWindow(
{
    content: 'Oh You Found Me!!!',
    size: new google.maps.Size(25,25),
    position: myLatlng
});


google.maps.event.addListener(map, 'zoom_changed', function() {
    zoomLevel = map.getZoom();

    if (zoomLevel == 16) {

        marker.visible = false;

        infowindow.open(map,marker);

    }
});

但如果我将这个marker.visibility改为这样:

but if I reverse the marker.visibility such that:

var marker = new google.maps.Marker({

    draggable: false,

    raiseOnDrag: false,

    clickable: true,

    icon: image,

    shadow: shadow,

    shape: shape,

    map: map,

    url: 'http://www.google.com/',



    visible: false,

    position: markerLatlng

});

google.maps.event.addListener(map, 'zoom_changed', function() {
    zoomLevel = map.getZoom();

    if (zoomLevel == 16) {

        marker.visible = true;

        infowindow.open(map,marker);

    }      
});

标记不会显示在地图上。

The marker won't show up on the map at all.

setVisible的正确方法是 marker.setVisible(false);

The proper way of setVisible is marker.setVisible(false);