Want zoom level in Geocoder

1,108 views
Skip to first unread message

Bimal

unread,
Aug 26, 2009, 6:42:54 AM8/26/09
to Google Maps JavaScript API v3
Hello
I am new to Google map. I am using this example to add Geocoder
feature in my site with Google Map
http://code.google.com/apis/maps/documentation/v3/examples/geocoding-simple.html

This is working fine but I want to add auto zoom feature for search
result.
Example, if I search for "China" then map displays it correctly but I
cannot get Zoom level dynamically. I am getting street view of China
but I want full map of china.
How can I do this ?

Thanks
- Bimal

Ben Appleton

unread,
Aug 26, 2009, 6:47:58 AM8/26/09
to google-map...@googlegroups.com
Hi Bimal,

See this post:
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/59112951d8eb18c3
The main method you need is Map .fitBounds()

Regards
Ben

Esa

unread,
Aug 26, 2009, 7:12:15 AM8/26/09
to Google Maps JavaScript API v3


On Aug 26, 1:47 pm, Ben Appleton wrote:

> See this post:http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...
> The main method you need is Map .fitBounds()

And the geocoder response includes LatLngBounds

geometry.viewport and
geometry.bounds

which can be used with Map.fitBounds()

http://koti.mbnet.fi/ojalesa/boundsbox/geocoderbounds.htm

Bimal

unread,
Aug 26, 2009, 7:17:02 AM8/26/09
to Google Maps JavaScript API v3
Thanks for fast reply

But this is not working
I have insterted the fitMap() function and call it in codeAddress()
function.

Please help me
Thanks

On Aug 26, 3:47 pm, Ben Appleton <apple...@google.com> wrote:
> Hi Bimal,
>
> See this post:http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...
> The main method you need is Map .fitBounds()
>
> Regards
> Ben
>
> On Wed, Aug 26, 2009 at 8:42 PM, Bimal<bimal4mo...@gmail.com> wrote:
>
> > Hello
> > I am new to Google map. I am using this example to add Geocoder
> > feature in my site with Google Map
> >http://code.google.com/apis/maps/documentation/v3/examples/geocoding-...

Ben Appleton

unread,
Aug 26, 2009, 7:31:00 AM8/26/09
to google-map...@googlegroups.com
Can you provide a link to your page? Thats helps debugging.

Bimal

unread,
Aug 26, 2009, 8:27:56 AM8/26/09
to Google Maps JavaScript API v3
Here is my page :
http://www.montotechnologies.com/geocode.html

I have added a dropdown box on top for Country selection. I am calling
a javascript function on select.



On Aug 26, 4:31 pm, Ben Appleton <apple...@google.com> wrote:
> Can you provide a link to your page?  Thats helps debugging.
>

Ben Appleton

unread,
Aug 26, 2009, 9:21:04 AM8/26/09
to google-map...@googlegroups.com
http://www.montotechnologies.com/geocode.html
fails when I press the "Geocode" button.

39: function codeAddress(country) {
40: //var address = document.getElementById("address").value;
41: var address = country.value;
42: if (geocoder) {
43: geocoder.geocode( { 'address': address}, function(results, status) {

On line 41 you write
var address = country.value;
country.value returns "Geocoder"

That's because you call codeAddress from the "Geocoder" button's
onclick handler:
<input type="button" value="Geocode" onclick="codeAddress(this)">

Ben Appleton

unread,
Aug 26, 2009, 9:25:17 AM8/26/09
to google-map...@googlegroups.com
If instead I select an item from your drop-down menu, you geocode the
address correctly but then call fitMap without the address.:

24 function fitMap (map) {
25 var bounds = new google.maps.LatLngBounds();
26 map.fitBounds(bounds);
27 //map.set_zoom(map.getBoundsZoomLevel(bounds));
28 //map.set_zoom(map.getBoundsZoomLevel(bounds));
29 map.set_center(bounds.getCenter());
30
31}

Line 25 creates an empty LatLngBounds.
Line 26 fits the map to the empty LatLngBounds. That causes the map
to zoom out to level 0.

You will need to call map.fitBounds() with the LatLngBounds returned
by the Geocoder.

On Wed, Aug 26, 2009 at 10:27 PM, Bimal<bimal...@gmail.com> wrote:
>

Bimal

unread,
Aug 26, 2009, 9:36:04 AM8/26/09
to Google Maps JavaScript API v3
Can you please provide codes to insert.
I am very new to Google Map API v3


On Aug 26, 6:25 pm, Ben Appleton <apple...@google.com> wrote:
> If instead I select an item from your drop-down menu, you geocode the
> address correctly but then call fitMap without the address.:
>
> 24 function fitMap (map) {
> 25 var bounds = new google.maps.LatLngBounds();
> 26 map.fitBounds(bounds);
> 27 //map.set_zoom(map.getBoundsZoomLevel(bounds));
> 28 //map.set_zoom(map.getBoundsZoomLevel(bounds));
> 29 map.set_center(bounds.getCenter());
> 30
> 31}
>
> Line 25 creates an empty LatLngBounds.
> Line 26 fits the map to the empty LatLngBounds.  That causes the map
> to zoom out to level 0.
>
> You will need to call map.fitBounds() with the LatLngBounds returned
> by the Geocoder.
>

Bimal

unread,
Aug 26, 2009, 10:58:42 AM8/26/09
to Google Maps JavaScript API v3
I get it working...
Thanks to all of you
Reply all
Reply to author
Forward
0 new messages