使用纬度/经度计算从点A到线段的距离 [英] Calculate the distance from point A to line segment using Lat /Lon

查看:126
本文介绍了使用纬度/经度计算从点A到线段的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GPS的Android应用程序。如果新位置(点C)距线段AB太远,我想知道是否有办法抛出GPS位置数据。我正在使用维基百科上的点对点线段公式。



到目前为止,我使用的代码是在我尝试使用经度和纬度坐标时返回NaN。

  private void verifyGPSLocation(Location start,Location end,Location current){
final double errorValue = 0.0000216;
double normalLength = Math.hypot(end.getLatitude() - start.getLatitude(),end.getLongitude() - start.getLongitude()); $()()()()()()()() ()))/ normalLength);
Log.e(Coooooord,normalLength + - + ret);

$ / code>

这是我的第一篇文章,请让我知道如果我没有这样做正确或有足够的信息。感谢您的帮助,我喜欢这个网站!

解决方案

我认为您使用的公式找到2个地理点之间的距离太简单了。由于地球的曲率,公式有点复杂。
看看这里,它提供了一个更准确的近似值。

也有一个Javascript例子,所以你可以通过一些语法调整轻松地将它改为Java。



<澄清之后,你似乎正在寻找一个点到两个地点之间地球上的一条路径的距离。查看上面链接中的跨轨道距离变化。

I am working on an Android app that uses the GPS. I would like to know if there is a way I can throw out GPS Location data if the "new location" (point C) is too far away from line segment AB. I am using the Point to Line Segment formula found on Wikipedia.

So far, the code I have is returning NaN when I try to use Latitude and Longitude coordinates.

private void verifyGPSLocation(Location start, Location end, Location current){
    final double errorValue = 0.0000216;
    double normalLength = Math.hypot(end.getLatitude() - start.getLatitude(), end.getLongitude() - start.getLongitude());
    double ret = Math.abs(((current.getLatitude() - start.getLatitude()) * (end.getLongitude() - start.getLongitude()) - (end.getLatitude() - start.getLatitude()))/normalLength );
    Log.e("Coooooord", normalLength+"--"+ret);
}

This is my first post so please let me know if I have not done this correctly or with enough information. Thanks for your help, I love this site!

解决方案

I think the formula you are using to find the distance between 2 geographic points is too simplistic. Due to the curvature of the earth, the formula is a bit more complicated. Have a look here, this provides a more accurate approximation.

There is a Javascript example too, so you can easily change it to Java with a few syntactical tweaks.

After clarification, you seem to be looking for the distance of a point to a path on the earth between two locations. Check out the cross-track distance variation in the link above.

这篇关于使用纬度/经度计算从点A到线段的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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