-1

Script for Chicago:

var current = new google.maps.LatLng(41.8333925, -88.0123393);
map.setCenter(current);

Script for Danville:

var current = new google.maps.LatLng(36.5925975, -79.5510265);
map.setCenter(current);

It work ok, but I must use for this setZoom.

So if I use:

map.setZoom(10);

This is good for Chicago, but for Danville it is too far (12 is good).

Is there a similar function to setZoom, which will bring me a map only to the boundaries of a given city? Chicago and Danville are only examples.

dimad
  • 1

1 Answers1

0

I think you can use this code :

var geocoder = new google.maps.Geocoder();
   geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        map.fitBounds(results[0].geometry.viewport);
      }
    });

Source

Kays Kadhi
  • 538
  • 6
  • 21