无法设置经度从 -180 到 0 的 LatLngBounds

unable to set a LatLngBounds with longitude from -180 to 0

本文关键字:LatLngBounds -180 设置 经度      更新时间:2023-09-26
当尝试设置新的 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);

等等。

JSFiddle 演示