尝试设置新的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之间有什么区别?没有。

您仍然可以确定所有四个季度的预测:

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 demo

关于javascript - 无法将经度从-180设置为0的LatLngBounds,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27107440/

10-13 01:04