How to use viewport results to set map scale

3,026 views
Skip to first unread message

Claus

unread,
Jul 6, 2010, 9:37:25 AM7/6/10
to Google Maps JavaScript API v3
geocoder returns a suggested viewport in its response

which I capture like with "results[0].geometry.viewport" in the JSON
response

I wanted to simply use the suggested viewport's lat lng for my map
zoom level instead of trying to code a switch which would zoom based
on the geometry.location_type response. See my current code below:

switch (results[0].geometry.location_type)
{
case "ROOFTOP":
map.setZoom(18);
break;
default:
map.setZoom(6);
}


Can I use something like setBounds(bounds:LatLngBounds)? If so what
would the sample code look like?

I tried :

map.setBounds(results[0].geometry.viewport)

but that did not work.


Rossko

unread,
Jul 6, 2010, 9:48:23 AM7/6/10
to Google Maps JavaScript API v3
> I tried :
> map.setBounds(results[0].geometry.viewport)
> but that did not work.

No, you can't just make syntax up.
Try the docs
http://code.google.com/apis/maps/documentation/javascript/reference.html#Map

Claus

unread,
Jul 6, 2010, 12:17:12 PM7/6/10
to Google Maps JavaScript API v3
> Try the docshttp://code.google.com/apis/maps/documentation/javascript/reference.h...

Thanks for the reply, got it to work after you pointed me in a
direction to research.
Reply all
Reply to author
Forward
0 new messages