尝试设置新的 LatLngBounds 时,对于世界的西南部,西南经度自动设置在世界的另一边,导致 LatLngBounds 不一致(西南比东北更东)
a = new google.maps.LatLng(-90, -180, true);
a.lng();
=> -180
b = new google.maps.LatLng(0, 0, true);
c = new google.maps.LatLngBounds(a, b);
c.getSouthWest().lng();
=> 180
问题似乎不在于 LatLng,而更多在于 LatLngBounds。它们是其他参数或其他方法吗,以便它可以代表世界的这个四分之一?
使用更多参数进行测试,只有西南经度始终设置为-180:http://jsfiddle.net/vr6ztq9z/1/
最佳答案
纬度:
在墨卡托投影中,最大北纬度不是 90,而是大约 85.05113 。在 JavaScript 中你可以这样做:
Math.atan(Math.sinh(Math.PI)) * 180 / Math.PI;
这样您就可以找到投影的真正的南北边缘。
经度:
经度 -180 度和 180 度有什么区别?没有任何。
您仍然可以识别投影的所有 4 个季度:
var maxLat = Math.atan(Math.sinh(Math.PI)) * 180 / Math.PI;
var center = new google.maps.LatLng(0, 0);
var sw = new google.maps.LatLng(-maxLat, 180);
var ne = new google.maps.LatLng(maxLat, -180);
// Southwest part of the world
new google.maps.LatLngBounds(sw, center);
// Southeast part of the world
new google.maps.LatLngBounds(center, sw);
等等。
关于javascript - 无法设置经度从 -180 到 0 的 LatLngBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107440/