detecting visible google map markers after setZoom

I'm using google map fitBounds, then I use map.setZoom to zoom-in one level (after google finds the best zoom level to fit my markers), then I want to check weather my markers are visible in viewport or not, how can I do so? it seems that map.getBounds().contains doesn't work, please take a look at this fiddle: fiddle

I want to check my marker is visible or not:

google.maps.event.addListenerOnce(map, "zoom_changed", function() {
        map.setZoom(map.getZoom()+2);
        if( map.getBounds().contains("35.700592","51.394773"))
alert('ok');   


         but there seems to be an error   
        //alert("the zoom level is now "+map.getZoom());
});

Why do you think "35.700592","51.394773" is a google.maps.LatLng? It is two strings separated by a comma.

This won't work:

google.maps.event.addListenerOnce(map, "zoom_changed", function() {
    map.setZoom(map.getZoom()+2);
    if( map.getBounds().contains("35.700592","51.394773"))
    alert('ok');   
});

This is the correct way to use "contains" (with a LatLng object):

google.maps.event.addListenerOnce(map, "zoom_changed", function() {
    map.setZoom(map.getZoom()+2);
    if( map.getBounds().contains(new google.maps.LatLng(35.700592,51.394773)))
    alert('ok');                
});

And you probably want to make an array containing your markers and use .getPosition() on the markers

http://jsfiddle.net/Npu36/10/embedded/result/

链接地址: http://www.djcxy.com/p/81572.html

上一篇: 使用Google Maps MapCanvasProjection“伪造”缩放级别

下一篇: 在setZoom之后检测可见的Google地图标记