如果地图上显示某个点

时间:2011-05-10 17:09:58

标签: google-maps-api-3

如何知道我的地图上是否有可见的点?

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

1 个答案:

答案 0 :(得分: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
}