Bounding box behavior

232 views
Skip to first unread message

Nick

unread,
Nov 26, 2011, 9:27:16 PM11/26/11
to google-map...@googlegroups.com

Hi everyone,

I already asked this question on stackoverflow, but this is probably the better place to ask:

I am using Googles Map API v3. Can somebody explain the behavior of the map's bounding boxes to me?

Depending on the zoom level these bounds behave weird - when I zoom in it works as expected - the bounds stretch from the lower left corner of the pane to the upper right corner. As soon as I zoom out it get weirds - the bounding box splits up. You can reproduce this with the google examples and the attached code. Just zoom out until the maximum after running the code.

The wrong bounding boxes are really annoying - e.g. markers in between are not in the bounds of the map, although they are visible.

http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html

http://www.spotdiving.com/bug.png

var viewportBox;
google.maps.event.addListener(this.map, 'idle', function(event)
{
    var bounds = map.getBounds();

    var ne = bounds.getNorthEast();
    var sw = bounds.getSouthWest();

    var viewportPoints = [
        ne, new google.maps.LatLng(ne.lat(), sw.lng()),
        sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
    ];

    if (viewportBox)
    {
        viewportBox.setPath(viewportPoints);
    } else
    {
        viewportBox = new google.maps.Polyline({
            path: viewportPoints,
            strokeColor: '#FF0000',
            strokeOpacity: 1.0,
            strokeWeight: 4
        });
        viewportBox.setMap(map);
    }
});

Rossko

unread,
Nov 27, 2011, 5:21:00 AM11/27/11
to Google Maps JavaScript API v3
> Depending on the zoom level these bounds behave weird - when I zoom in it
> works as expected - the bounds stretch from the lower left corner of the
> pane to the upper right corner. As soon as I zoom out it get weirds - the
> bounding box splits up. You can reproduce this with the google examples and
> the attached code.

I tried zooming out on the example you gave, but no box was drawn.

I'm guessing the question may be recast as "I'm having trouble drawing
rectangler bigger than a hemisphere"?

See
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/2b18cc2d32085ed8/cea7f4e3ccc0285a
for an example

Nick

unread,
Nov 27, 2011, 8:08:59 AM11/27/11
to google-map...@googlegroups.com
Thank you for your reply!

Did you paste the code before zooming? When I paste it to the console and zoom out afterwards I can see it. Just tried it using Safari, I have not tested it in another browser.

Well, what I am trying to achieve is the following: 

I want to know whether a marker is visible or not. Hence I wanted to check if the bounds of the map contain the position of this marker. This does not work when the bounding box of the map behaves like that, because a marker that is in between these rectangles will not be within their bounds.

Is there a better way to check the visibility?
Reply all
Reply to author
Forward
0 new messages