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

标签 javascript google-maps-api-3

尝试设置新的 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 demo

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

相关文章:

带有参数的Javascript函数有一个函数吗?

javascript - 为什么我的全局变量在 JSFiddle 上被覆盖了?

javascript - 过滤并删除数组

javascript - 当内容设置为 jQuery 对象时,谷歌地图信息窗口的大小不正确以适合图像

javascript - 需要从google map API获取纬度和经度

javascript - 如何使用 JavaScript/jQuery 自动定期更改网页的标题?

javascript - 如何使用下拉菜单中的地点库在 Google map 上显示标记?

java - 在java中使用谷歌翻译API将英语转换为阿拉伯语文本

javascript - 如何将 "generate"唯一变量?

javascript - 还有其他方法可以将 JS 连接到 HTML 吗?