Javascript 世界的最大纬度和经度边界 - Google Maps API LatLngBounds()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11849636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maximum Lat and Long bounds for the world - Google Maps API LatLngBounds()
提问by Ryan Brodie
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?
默认情况下,谷歌地图地形视图具有无限的地图图块平移。您可以使用它LatLngBounds()
来限制这一点,但是我应该使用什么来将视口设置为地球而不是地图区域之外的最大和最小坐标?
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.
我试过(+90, -180)(-90,180)
没有运气。
回答by nelsonic
The links provided by @Marcelo & @Doc are goodfor understanding the derivationof the Lat Lng:
通过@Marcelo&@doc提供的链接是很好理解的推导的纬度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
- 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 justwant an answer for the maximum boundsfor Google Maps:
但是,如果你只是想在回答最大边界为谷歌地图:
Latitude: -85 to +85
(actually -85.05115 for some reason)
Latitude: -85 to +85
(实际上 -85.05115 出于某种原因)
Longitude: -180 to +180
Longitude: -180 to +180
Tryit for yourself on the Google Maps:
在 Google 地图上亲自尝试:
(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
获得答案后,请编辑此 wiki(或更新您的问题)。谢谢
回答by Marcelo
See this postin the old Google Groups, which describes the math of the projection.
请参阅旧版 Google Groups 中的这篇文章,其中描述了投影的数学原理。
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....
地图不是从 85 度开始,而是从使地图呈方形的角度开始。这可以简单地计算为: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.
请注意,该帖子中的 tile 计算适用于旧 API V2,但投影应该相同。
回答by Sumit Arora
You may do the following to get the Max Lat and Long bounds of the world with the help of Google Maps :
您可以在 Google Maps 的帮助下执行以下操作以获取世界的最大纬度和经度:
1:Set the Zoom Level 1 of Google Maps While setting up the Google Map Stuff :
1:设置 Google Maps 的缩放级别 1 在设置 Google Map Stuff 时:
mapOptions = {
zoom: 1,
.....
}
2.Do the following to get NorthEast and SouthWest Bound of this Map :
2.执行以下操作以获取此地图的东北和西南边界:
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();
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 :
3.它会给你以下东北和西南边界:
NorthEast Latitude : 89.45016124669523
NorthEast Longitude : 180
SouthWest Latitude : -87.71179927260242
Southwest Longitude : -180
东北纬度:89.45016124669523
东北经度:180
西南纬度:-87.71179927260242
西南经度:-180
Similarly on Zoom Level- 0 , It give following points :
同样在 Zoom Level-0 上,它给出了以下几点:
NorthEast Latitude : 89.99346179538875
NorthEast Longitude : 180
SouthWest Latitude : -89.98155760646617
Southwest Longitude : -180
东北纬度:89.99346179538875
东北经度:180
西南纬度:-89.98155760646617
西南经度:-180
Above trick helped me to solve my business problem which required max lat/long.
以上技巧帮助我解决了需要最大纬度/经度的业务问题。
回答by Doc Roms
for more details in GPS values you can read thisarticle.
有关 GPS 值的更多详细信息,您可以阅读这篇文章。
Article explain that :
文章解释说:
- Latitude is the distance from the Equator measured along the Greenwich Meridian. This distance is measured in degrees and ranges between 0o to 90o North and South.
- Longitude is the distance from the Greenwich Meridian measured along the Equator. This distance is measured in degrees and ranges from 0o to 180o East and West.
- 纬度是沿格林威治子午线测量到赤道的距离。该距离以度为单位,范围在 0° 到 90° 南北之间。
- 经度是沿赤道测量到格林威治子午线的距离。该距离以度为单位,范围从东、西 0 度到 180 度。