2011-05-10 34 views
3

如何知道点是否在我的地图上可见?如果一个点在地图上可见

var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng)); if map.getbounds()。contains(point)...

回答

7

如果通过可见,你的意思是如果一个点在地图的可见区域(视口)内;

// assuming you initialized your map 

var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng)); 
var currentBounds = map.getBounds() // get bounds of the map object's viewport 

if(currentBounds.contains(point)){ 
    // your location is inside your map object's viewport 
}else{ 
    // your location is out of the bounds of the map's visible viewport 
} 
+0

我以为getBounds不在V3?! – Bertaud 2011-05-10 21:26:17

+1

这是,[检查API参考](http://code.google.com/intl/en-EN/apis/maps/documentation/javascript/reference.html#Map) – solidrevolution 2011-05-11 04:55:24

+0

API参考链接现在已经死了^^ – mtness 2018-02-16 17:50:30

相关问题