Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a point is visible on the map

How to know if a point is visible on my map ?

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

like image 901
Bertaud Avatar asked Feb 25 '23 06:02

Bertaud


1 Answers

If by visible you are meaning if a point is inside a map's visible area (viewport);

// 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
}
like image 116
solidrevolution Avatar answered Mar 29 '23 03:03

solidrevolution