jhanifen
jhanifen

Reputation: 4591

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?

Upvotes: 18

Views: 12839

Answers (2)

Vijay Shegokar
Vijay Shegokar

Reputation: 2522

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.

Upvotes: 2

mhyfritz
mhyfritz

Reputation: 8522

I guess you want

map.getBounds().contains(marker.getPosition())

Upvotes: 41

Related Questions