奇怪的大圆距离计算
我在使用地图计算大圆距离时遇到一些问题。
上下文:http://airports.palzkill.de/search/
地图应该作为大圆距离搜索地图 - 您移动圆心标记或半径标记,圆就会变小或变大。出于调试目的,框标题字段显示计算出的距离(以公里为单位)。
仅当圆心接近 0/0 并且半径标记距它不太远时,此功能才可以正常工作。 你将任何一个标记移动到“极端”的次数越多,整个事情就会越偏离,只会产生垃圾。
这是用于计算更新的代码,您还可以在 JS 文件 js.js 中找到整个代码,第 146 到 184 行:
function searchmapupdate()
{
rad_lat_radiuspos = (circleradiusmarker.getPosition().lat()*Math.PI/180);
rad_lon_radiuspos = (circleradiusmarker.getPosition().lng()*Math.PI/180);
rad_lat_circlecenter = (circlecentermarker.getPosition().lat()*Math.PI/180);
rad_lon_circlecenter = (circlecentermarker.getPosition().lng()*Math.PI/180);
circleradiusvar = Math.acos(Math.sin(rad_lat_circlecenter)*Math.sin(rad_lat_radiuspos)+Math.cos(rad_lat_circlecenter)*Math.cos(rad_lon_radiuspos)*Math.cos(rad_lon_circlecenter-rad_lon_radiuspos))*6371.01*1000;
if (isNaN(circleradiusvar)==false) circle.setOptions({center:circlecentermarker.getPosition(), radius:circleradiusvar});
document.getElementById("mapsearchhead").innerHTML = Math.round(circleradiusvar/1000);
}
由于整个过程确实计算了一些正确的输出,我认为数学本身并不是完全错误的,我猜猜只是缺少一些“矫正”的东西? 不幸的是,我在三角学方面非常糟糕,所以我不知道这里可能出了什么问题,甚至不知道从哪里开始寻找如何解决它的想法。
Marco
P.S.:我知道由于投影的球形性质,整个事物必须在极点周围表现“反直觉”。但这并不能真正解释当您将两个标记移动到靠近赤道周围的日期变更线(0/179、0/-179)时会发生什么。
I have some problems with a great circle distance calculation using a map.
Context: http://airports.palzkill.de/search/
The map is supposed to work as a great circle distance search map - you move the circles center marker or the radius marker, and the circle gets smaller or larger. For debug purposes, the boxes title field shows the calculated distance in km.
This only works fine as long as the circle center is close to 0/0, and the radius marker is not too far away from it.
The more you move either of the markers to "extremes", the more off some tangent the whole thing goes and produces nothing but crap.
This is the code used for calculating the updates, you can also find the entire code in the JS file js.js, lines 146 to 184:
function searchmapupdate()
{
rad_lat_radiuspos = (circleradiusmarker.getPosition().lat()*Math.PI/180);
rad_lon_radiuspos = (circleradiusmarker.getPosition().lng()*Math.PI/180);
rad_lat_circlecenter = (circlecentermarker.getPosition().lat()*Math.PI/180);
rad_lon_circlecenter = (circlecentermarker.getPosition().lng()*Math.PI/180);
circleradiusvar = Math.acos(Math.sin(rad_lat_circlecenter)*Math.sin(rad_lat_radiuspos)+Math.cos(rad_lat_circlecenter)*Math.cos(rad_lon_radiuspos)*Math.cos(rad_lon_circlecenter-rad_lon_radiuspos))*6371.01*1000;
if (isNaN(circleradiusvar)==false) circle.setOptions({center:circlecentermarker.getPosition(), radius:circleradiusvar});
document.getElementById("mapsearchhead").innerHTML = Math.round(circleradiusvar/1000);
}
Since the whole thing does calculate some correct output I assume the math itself is not totally wrong, I guess there is just some "correctional" stuff missing?
Unfortunately I am absolutely lousy at trigonometry, so I dont have a clue what might be wrong here, or even where to start searching for ideas about how to fix it.
Marco
P.S.: I know that due to the spherical nature of the projection, the whole thing has to act "counter-intuitive" around the poles. But that doesnt really explain what happens when you move both markers close to the date line around the equator (0/179, 0/-179).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,在实现了更多代码之后,我实际上发现了方程中的一个错误:在我应该使用 lat 的地方使用了 lon 。
是的,我现在非常尴尬 - 并且同样恼火,我花了 5 个小时查看条款,却没有更早发现这个明显的错误。
Okay, after implementing some more code, I actually discovered an error in the equation: Using lon where I should have used lat.
And yes, I am very embarassed now - and equally annoyed, having spent 5 hours looking at the terms and not finding this obvious error earlier.