1
votes

I check like this: enter code here var point = new g.LatLng(parseFloat(lat),parseFloat(lng)); var bounds = map.getBounds(); if (bounds.contains(point)) { the point is in the viewport }

But when I change the zoom level, thefore the coordinates of the viewport, the "invisible" point is NOT detected as "visible", I mean in the viewport. Point is not a marker !

2

2 Answers

1
votes

I wrote a hack that might work in your scenario. As far as I tested, it works when there's not a lot of the world repeated. I know this hack is unreliable if the world is displayed twice or more. So if you can set the map's minZoom, you would prevent such cases.

The idea is to divide the map in a left and right half, and check whether the marker is in either half.

Here's the hack, use carefully

http://jsfiddle.net/QeR2D/3/

0
votes

If you have more than the whole circumference of the Earth in your viewport, things can go wrong.

The left-hand edge may be further east than the right-hand edge. map.getBounds() gets the wrong result in this case.

The left-hand edge may be west of the right-hand edge, but area defined by the longitudes of both may not include the point of interest.

Here's an image of a map I developed for another answer which demonstrates that. The left-hand edge is at 83°E and the right-hand edge at 162°E. The markers are at 54°W and 8°W and neither are within map.getBounds() — they don't lie between 83°E and 162°E — even though they are obviously on the map.

I'm not aware of any method in the API which allows this to be catered for.