Skip to main content
Added resolution
Source Link

With Google Maps I can enter a single lat/lng coordinate and the map is drawn with that lat/lng in the center.

What I'd like to be able to do is enter two coordinate pairs, say the southwest coordinate and the northeast coordinate, and have a Google Map displayed with the appropriate zoom so that the map fills the bounds defined by those coordinates.

Is this possible? If so, how?

Thanks

And the Answer is... Go to Google Maps Code Playground!

Per Taylor's suggestion, I went to the Google Maps Code Playground and entered the following code and was able to get a centered map with the appropriate zoom level bounded by the coordinate pair.

function initialize() {
  var mapDiv = document.getElementById('map-canvas');
  var map = new google.maps.Map(mapDiv, {
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
  var southWest = new google.maps.LatLng(..., ...);
  var northEast = new google.maps.LatLng(..., ...);
  var bounds = new google.maps.LatLngBounds(southWest,northEast);
  map.fitBounds(bounds);
}

With Google Maps I can enter a single lat/lng coordinate and the map is drawn with that lat/lng in the center.

What I'd like to be able to do is enter two coordinate pairs, say the southwest coordinate and the northeast coordinate, and have a Google Map displayed with the appropriate zoom so that the map fills the bounds defined by those coordinates.

Is this possible? If so, how?

Thanks

With Google Maps I can enter a single lat/lng coordinate and the map is drawn with that lat/lng in the center.

What I'd like to be able to do is enter two coordinate pairs, say the southwest coordinate and the northeast coordinate, and have a Google Map displayed with the appropriate zoom so that the map fills the bounds defined by those coordinates.

Is this possible? If so, how?

Thanks

And the Answer is... Go to Google Maps Code Playground!

Per Taylor's suggestion, I went to the Google Maps Code Playground and entered the following code and was able to get a centered map with the appropriate zoom level bounded by the coordinate pair.

function initialize() {
  var mapDiv = document.getElementById('map-canvas');
  var map = new google.maps.Map(mapDiv, {
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
  var southWest = new google.maps.LatLng(..., ...);
  var northEast = new google.maps.LatLng(..., ...);
  var bounds = new google.maps.LatLngBounds(southWest,northEast);
  map.fitBounds(bounds);
}

Tweeted twitter.com/#!/StackGIS/status/297465230097788930
typo in title
Link
Mapperz
  • 50.2k
  • 9
  • 75
  • 133

Can I view a Google Maps map by bounding latitutdelatitude and longitude coordinates

Source Link

Can I view a Google Maps map by bounding latitutde and longitude coordinates

With Google Maps I can enter a single lat/lng coordinate and the map is drawn with that lat/lng in the center.

What I'd like to be able to do is enter two coordinate pairs, say the southwest coordinate and the northeast coordinate, and have a Google Map displayed with the appropriate zoom so that the map fills the bounds defined by those coordinates.

Is this possible? If so, how?

Thanks