map.fitBounds(map.getBounds()) zooms out map!

3,376 views
Skip to first unread message

Stephen

unread,
Mar 7, 2011, 4:49:49 PM3/7/11
to google-map...@googlegroups.com
I am trying to sync two maps by passing the bounds from one to the other and I find that it doesn't work. Instead the second map is always one zoom level lower then the other. In fact running code like
map.fitBounds(map.getBounds())

causes the map to zoom out!

For example see the attached slightly modified hello maps example to watch the map zoom out as this is called repeatedly in a timeout.

Is this expected behavior? At the very least I would expect to see some nuance in the API documentation that would make this behavior correct.

I suppose slightly shrinking my bounds on the other side will solve the issue but this seems wrong.

Thanks
Stephen
simpleMap.html

Stephen

unread,
Mar 7, 2011, 4:58:20 PM3/7/11
to google-map...@googlegroups.com
Just to clarify, I know that there are other ways to accomplish this in a simple case where I have two google maps (e.g. center and zoom), however my map is part of an ecosystem where it interacts with other components, and I am trying to support an "API" that allows other components (perhaps not map based) to set its view by passing a desired bounds.

Thanks
Stephen

Michael Geary

unread,
Mar 7, 2011, 5:02:03 PM3/7/11
to google-map...@googlegroups.com, Stephen
I think the V3 API puts a little padding around the bounds you give it when you call fitBounds(). It would be nice if there were an option to control this, especially if you could control it individually for the four edges (like CSS padding/margin).

If the maps are the same dimensions, you could do it like this:

    map2.setCenter( map1.getCenter() );
    map2.setZoom( map1.setZoom() );

-Mike

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Rossko

unread,
Mar 7, 2011, 8:12:17 PM3/7/11
to Google Maps JavaScript API v3
> I think the V3 API puts a little padding around the bounds you give it when
> you call fitBounds().

I think it may allow for the controls on the map, including Google
logo etc.

Esa

unread,
Mar 7, 2011, 10:06:21 PM3/7/11
to Google Maps JavaScript API v3
Syncing two (or more) maps together is very simple by binding them
together by bindTo().
http://koti.mbnet.fi/ojalesa/v3/dual.htm

There are lines

map_2.bindTo('zoom' ,map_1);
map_2.bindTo('center' ,map_1);
map_2.bindTo('mapTypeId' ,map_1);

that take care about syncing and even initializing of map_2.

Stephen

unread,
Mar 9, 2011, 12:43:05 PM3/9/11
to Google Maps JavaScript API v3
Just to make this thread complete, documentation will apparently be
updated to explain this behavior. See http://code.google.com/p/gmaps-api-issues/issues/detail?id=3117

Stephen

On Mar 7, 10:06 pm, Esa <esa.ilm...@gmail.com> wrote:
> Syncing two (or more) maps together is very simple by binding them
> together by bindTo().http://koti.mbnet.fi/ojalesa/v3/dual.htm
Reply all
Reply to author
Forward
0 new messages