Hi,

I've just finished an project using Google Map APIs and have a way to zoom
in directly on a country.
I have a textfield to help user could input country which zoom to.

You can call this method when hit on button or onchange of textfield.
Hope you satisfied with it.

See my code below:

function zoomToLocation(address){
if(address){
        var geo = new GClientGeocoder();
        geo.getLocations(address, function (result){

              // ===== Look for the bounding box of the first result =====
              var N = result.Placemark[0].ExtendedData.LatLonBox.north;
              var S = result.Placemark[0].ExtendedData.LatLonBox.south;
              var E = result.Placemark[0].ExtendedData.LatLonBox.east;
              var W = result.Placemark[0].ExtendedData.LatLonBox.west;
              var bounds = new GLatLngBounds(new GLatLng(S,W), new
GLatLng(N,E));
              // Choose a zoom level that fits
              var zoom = map.getBoundsZoomLevel(bounds);
              map.setCenter(bounds.getCenter(),zoom);
         }
      );
    }
}

Phu.


2009/9/6 Marcelo <[email protected]>

>
> See:
> http://nearby.org.uk/downloads.html
> Fifth item on the list: "World Country Bounding Boxes"
> http://nearby.org.uk/coords/countries.csv
>
> --
> Marcelo - http://maps.forum.nu
> --
>
>
>
>
> On Sep 6, 6:38 pm, Marc <[email protected]> wrote:
> > Great thanks!
> >
> > I'll make an script that automaticly geocodes all the countries and
> > insert them in a DB for further use :-)
> >
> > Regards,
> >
> > Marc
> >
> > On 6 sep, 17:57, "[email protected]" <[email protected]> wrote:
> >
> > > On Sep 6, 11:21 am, Marc <[email protected]> wrote:
> >
> > > > Hi,
> >
> > > > Is there a way to zoom in directly on a country with the google maps
> > > > api?
> >
> > > You need to know the the bounds of the country.  If you use the
> > > geocoder, it returns a LatLonBox as extended data that can be used.
> >
> > > Mike Williams's example:http://econym.org.uk/gmap/example_geo3.htm
> >
> > > Or you could calculate and store the zoom and center for each country
> > > in your database (or xml file).
> >
> > >   -- Larry
> >
> > > > For example when I go tohttp://maps.google.com/andsearchfor Spain,
> > > > I'll see a nice full view of Spain. Is there a way to do something
> > > > like this in the google maps api as well?
> >
> > > > Thanks for answering!
> >
> > > > Best regards,
> >
> > > > Marc
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to