fitBounds set the zoom 1 step behind

230 views
Skip to first unread message

Dones

unread,
Sep 12, 2009, 1:03:23 PM9/12/09
to Google Maps JavaScript API v3
Hi guys, i've a problem with fitBounds function.

1)In the first page i get the bounds of the map with getBounds
function.

2) I send these bounds as parameters to another page.

3) with fitBounds(bounds) function in the new page, i'd like to set
the best zoom of the map to get the same map as the previous page.

bounds=new google.maps.LatLngBounds(SWlatLng, NElatLng);
map.fitBounds(bounds);

Unluckily the zoom of the map is one step smaller than the previous
map, and if i repeat this action next times, the zoom get "out" again
and again...

Can u help me?

Barry Hunter

unread,
Sep 12, 2009, 1:46:12 PM9/12/09
to google-map...@googlegroups.com
2009/9/12 Dones <manuel...@gmail.com>:
Not really. We need to see what you see, and by far the best way to do
that is provide a link to your map..


> >
>



--
Barry

- www.nearby.org.uk - www.geograph.org.uk -

Dones

unread,
Sep 12, 2009, 2:34:52 PM9/12/09
to Google Maps JavaScript API v3
ok i'll post an example...

On 12 Set, 19:46, Barry Hunter <barrybhun...@googlemail.com> wrote:
> 2009/9/12 Dones <manueledo...@gmail.com>:
Message has been deleted

Dones

unread,
Sep 12, 2009, 4:10:57 PM9/12/09
to Google Maps JavaScript API v3
Here we go...
http://www.manueledones.altervista.org/page1.html

Where i'm getting wrong?

Thanks

Barry Hunter

unread,
Sep 12, 2009, 4:52:35 PM9/12/09
to google-map...@googlegroups.com
Ah I see now!

What I think is happening, is 'fitBounds' tries to find a zoom level
that allows the whole of the 'bounds' to be visible. Because the map
has a logo and nav buttons etc, the whole map area would not permit
the required area to be totally visible.

If for example you where using fitBounds to layout a groundoverlay, or
even a bunch of markers, you probably dont some of them hidden behind
the chrome of the map.


Course dont know what you actully trying to do*, but could you perhaps
send the zoom level though?

Or if you know its always going to be used in this way you could
reasonably safely just zoom in a step?

Or could maybe try using disableDefaultUI and only enable controls
after the fitBounds - but probably the logo will still get in the
way...


* another reason a link to your actual map rather than just a demo is
sometimes useful too.



2009/9/12 Dones <manuel...@gmail.com>:

Esa

unread,
Sep 12, 2009, 6:23:11 PM9/12/09
to Google Maps JavaScript API v3
Good catch. I tried it with

map.fitBounds(map.getBounds());

And it zooms out one level. It really seems that there are some
paddings in fitBounds() calculation.
Message has been deleted
Message has been deleted

Dones

unread,
Sep 13, 2009, 3:09:43 AM9/13/09
to Google Maps JavaScript API v3
Oh understood...

Yes i think i can do what i want passing the coordinates of the center
and the zoom, and in the second map center it with setCenter and zoom
it with setZoom.

Well i just want to have in the second map the same location and zoom
of the previous one...

I don't know why i get an error in the second page, but u can see the
code...i think it could work now...
http://www.manueledones.altervista.org/page2.html
Message has been deleted

Dones

unread,
Sep 13, 2009, 6:15:04 AM9/13/09
to Google Maps JavaScript API v3
Ok passing the coordinates of center and the zoom it works great. The
problem now is when u have to set the map after a geocode request..

If u search a city for example, the Geocode Response Object returns
this:
{types[]: String,
formatted_address: String,
address_components[]: {
short_name: String,
long_name: String,
types[]: String
},
geometry: {
location: LatLng,
location_type: GeocoderLocationType,
viewport: LatLngBounds,
bounds: LatLngBounds?
}

}

...so i haven't the zoom to have the best view of the city (or street)
but just the bounds...

So the only way i can see is to use fitBounds function...

is it clear? Maybe i'm going to post another example...

On 13 Set, 09:09, Dones <manueledo...@gmail.com> wrote:
> Oh understood...
>
> Yes i think i can do what i want passing the coordinates of the center
> and the zoom, and in the second map center it with setCenter and zoom
> it with setZoom.
>
> Well i just want to have in the second map the same location and zoom
> of the previous one...
>
> I don't know why i get an error in the second page, but u can see the
> code...i think it could work now...http://www.manueledones.altervista.org/page2.html
Reply all
Reply to author
Forward
0 new messages