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

85,346

Solution 1

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

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:

(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

Solution 2

See this post in the old Google Groups, which describes the math of the projection.

Quote:

the map doesn't start at 85 degrees, but rather the degree that makes the map square. This is can be simply calaculated as: atan(sinh(PI)) *180 / PI = 85.05112878....

Note that the tile calculation in that post is for the old API V2, but the projection should be the same.

Solution 3

You may do the following to get the Max Lat and Long bounds of the world with the help of Google Maps :

1: Set the Zoom Level 1 of Google Maps While setting up the Google Map Stuff :

mapOptions = {
                zoom: 1,
 .....
}

2. Do the following to get NorthEast and SouthWest Bound of this Map :

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

     // NorthEast Latitude : 89.45016124669523
     var latNEValue =  map.getBounds().getNorthEast().lat();
    // NorthEast Longitude : 180
     var longNEValue = map.getBounds().getNorthEast().lng();
     // SouthWest Latitude : -87.71179927260242
     var latSWValue =  map.getBounds().getSouthWest().lat();
     // Southwest Latitude :  -180
     var longSWValue = map.getBounds().getSouthWest().lng();

3. It will give you following NorthEast and SouthWest Bounds :

NorthEast Latitude : 89.45016124669523

NorthEast Longitude : 180

SouthWest Latitude : -87.71179927260242

Southwest Longitude : -180

Similarly on Zoom Level- 0 , It give following points :

NorthEast Latitude : 89.99346179538875

NorthEast Longitude : 180

SouthWest Latitude : -89.98155760646617

Southwest Longitude : -180

Above trick helped me to solve my business problem which required max lat/long.

Solution 4

for more details in GPS values you can read this article.

Article explain that :

  • Latitude is the distance from the Equator measured along the Greenwich Meridian. This distance is measured in degrees and ranges between 0º to 90º North and South.
  • Longitude is the distance from the Greenwich Meridian measured along the Equator. This distance is measured in degrees and ranges from 0º to 180º East and West.
Share:
85,346

Related videos on Youtube

Ryan Brodie
Author by

Ryan Brodie

brod.ie

Updated on December 04, 2020

Comments

  • Ryan Brodie
    Ryan Brodie over 3 years

    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.

    • Marcelo
      Marcelo almost 12 years
      On a mercator projection, latitude goes up to 85 and -85, not 90.
    • user2357112
      user2357112 almost 3 years
      The Mercator projection is not limited to latitudes from 85° to -85°. It just becomes increasingly distorted at extreme latitudes, and Google Maps cuts the projection off at around those latitudes.
  • Ryan Brodie
    Ryan Brodie almost 12 years
    So in the short, sample max and min coordinates for NW point and SW?
  • Doc Roms
    Doc Roms almost 12 years
    It's strange, when you look the official google map API doc it's really between 90/-90 for lattitude and 180/-180 for longitude, in your latlong declaration, you don't reverse latitude and longitude?
  • Ryan Brodie
    Ryan Brodie almost 12 years
    All I'm looking for is tested, working maximum minimum coordinates?
  • Ryan Brodie
    Ryan Brodie almost 12 years
    Nope, my code works fine for the US demographic latlng bounds.
  • Marcelo
    Marcelo almost 12 years
    Then read the post, understand it and test the coordinates. I'm not going to do your homework for you, kiddo.
  • Simon
    Simon almost 9 years
    Thanks. I had to use the following for java: private static final LatLngBounds EARTH = new LatLngBounds( new LatLng(-84.9, -180), // top left corner of map new LatLng(84.9, 180) // bottom right corner );
  • Paul Smith Racing
    Paul Smith Racing about 6 years
    From developers.google.com/maps/documentation/javascript/referenc‌​e/3/… LatLngBounds are SW corner (-85, -180) to NE corner (+85, +180), rather than top-left to bottom-right in the answer.
  • Harry Stylesheet
    Harry Stylesheet over 5 years
    Tried this in polyline tool but does not seem te give the enitre area, this is a very common issue. It is however the biggest and smallest possible longitude and latitude value. keene.edu/campus/maps/tool/…