Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API 3 - Check if marker is in view

I see that there is a getVisible call, but that only checks if the marker is on the map NOT if the marker is in the current view.

I want to check if the marker is in the current view bounds?

like image 486
jhanifen Avatar asked Jun 02 '11 19:06

jhanifen


2 Answers

I guess you want

map.getBounds().contains(marker.getPosition())
like image 50
mhyfritz Avatar answered Sep 24 '22 18:09

mhyfritz


You need to tell map that your markers should be contained within view by adding following code

google.maps.event.addListener(map, 'bounds_changed', function() {
    map.getBounds().contains(marker.getPosition()) 
});

Here bound_changed event is triggered.

like image 27
Vijay Shegokar Avatar answered Sep 23 '22 18:09

Vijay Shegokar