无法设置经度从 -180 到 0 的 LatLngBounds [英] unable to set a LatLngBounds with longitude from -180 to 0

查看:11
本文介绍了无法设置经度从 -180 到 0 的 LatLngBounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试设置新的 LatLngBounds 时,对于世界的西南四分之一,西南经度会自动设置在世界的另一端,导致 LatLngBounds 不一致(西南比东北更靠东)

When trying to set a new LatLngBounds, for the southwest quarter of the world, the SouthWest longitude is automatically set at the other side of the world, leading to an unconsistent LatLngBounds (SouthWest is more east than NorthEast)

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 中.它们是否是其他参数或其他方法,以便它可以代表这四分之一的世界?

The problem seems not to be in the LatLng, but more in the LatLngBounds. Are they other params or other ways to do it so it can represent this quarter of the world ?

使用更多参数进行测试,只有西南经度始终设置为-180:http://jsfiddle.net/vr6ztq9z/1/

Tests with more parameters, only southwest longitude is always set to -180 : http://jsfiddle.net/vr6ztq9z/1/

推荐答案

纬度:

在墨卡托投影中,最大北纬不是 90,而是大约 85.05113.在 JavaScript 中你可以这样做:

On a Mercator projection, the maximum north latitude is not 90, but something around 85.05113. In JavaScript you can do:

Math.atan(Math.sinh(Math.PI)) * 180 / Math.PI;

这样您就可以找到投影的真正的南北边缘.

This way you can find the real north and south edges of the projection.

经度:

-180 度和 180 度的经度有什么区别?没有任何.

What's the difference between a longitude of -180 and 180? None.

您仍然可以确定预测的所有 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 演示

这篇关于无法设置经度从 -180 到 0 的 LatLngBounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆