Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum Lat and Long bounds for the world - Google Maps API LatLngBounds()

The Google Maps terrain view by default has unlimited panning of the map tile. You can use LatLngBounds() to limit this, but what are the maximum and minimum coordinates I should use to set the viewport as just the earth and not outside the map region?

Coordinates for North America:

var strictBounds = new google.maps.LatLngBounds(     new google.maps.LatLng(28.70, -127.50),      new google.maps.LatLng(48.85, -55.90) ); 

I've tried (+90, -180)(-90,180) to no luck.

like image 281
Ryan Brodie Avatar asked Aug 07 '12 15:08

Ryan Brodie


People also ask

What is the daily limit for Google Maps API?

While there is no maximum number of requests per day, the following usage limits are in place for the Maps JavaScript API: 30,000 requests per minute. 300 requests per minute per IP address. In the Google Cloud Console, this quota is referred to as Map loads per minute per user.

What is Google Maps Latlngbounds?

An immutable class representing a latitude/longitude aligned rectangle.

How do you get bounds on Google Maps?

getBounds() in Google Maps API v3 But in API v3 you will get “bounds is undefined” error. So to get our latitude and longitude we need to move getBounds(), to some event listener. Description of bounds_changed in documentation is: “This event is fired when the viewport bounds have changed.”


1 Answers

The links provided by @Marcelo & @Doc are good for understanding the derivation of the Lat Lng:

  • http://www.cienciaviva.pt/latlong/anterior/gps.asp?accao=changelang&lang=en
  • https://groups.google.com/forum/?hl=en&fromgroups=#!msg/google-maps-api/oJkyualxzyY/pNv1SE7qpBoJ
  • https://en.wikipedia.org/wiki/Mercator_projection#Mathematics_of_the_Mercator_projection

But if you just want an answer for the maximum bounds for Google Maps:

Latitude: -85 to +85 (actually -85.05115 for some reason)

Longitude: -180 to +180

Try it for yourself on the Google Maps:

  • https://maps.google.com/?q=85,180
  • https://maps.google.com/?q=-85.05115,180

(You may need to Zoom Out. See how the pin is at the "edge" of the world - these are the limits)

So in your code Try:

var strictBounds = new google.maps.LatLngBounds(     new google.maps.LatLng(85, -180),           // top left corner of map     new google.maps.LatLng(-85, 180)            // bottom right corner ); 

Please edit this wiki (or update your question) once you have the answer. Thanks

like image 188
2 revs, 2 users 98% Avatar answered Sep 22 '22 22:09

2 revs, 2 users 98%