jaget
jaget

Reputation: 2219

jQuery ui google map check if marker is in view

I am using http://code.google.com/p/jquery-ui-map/

I am trying to find a way when looping through markers, of finding out if the markers are visible within the current viewport.

Does anybody know how to do this. I have tried isVisible()

Upvotes: 1

Views: 1017

Answers (2)

johansalllarsson
johansalllarsson

Reputation: 927

In the beta version there is a inViewport, see jquery google maps plugin filter by property

Upvotes: 0

Tomas
Tomas

Reputation: 59435

Don't know about jquery-ui-map, but in the raw google maps api v3 it's fairly simple:

var bnd = map.getBounds();
var ne = bnd.getNorthEast();
var sw = bnd.getSouthWest();
var pos = marker.getPosition();
if (pos.lat() >= sw.lat() && pos.lat() <= ne.lat() &&
    pos.lng() >= sw.lng() && pos.lng() <= ne.lng()) { // marker is in view
    ....
}

Upvotes: 1

Related Questions