计算两个位置之间距离的最佳方法

计算两个位置之间距离的最佳方法

本文介绍了Android:计算两个位置之间距离的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个主题上进行了一些研究,但有很多意见并没有给出清晰的图像。我的问题是这样的:我正在开发一个基于gps的Android应用程序,至于我想知道我的当前位置由Androids LocationManager指定的位置和其他位置之间的距离。我尝试了Haversine公式,一个余弦定律公式,然后我发现Android SDK给了我一个简单的函数Location.distanceTo(Location) - 我不确定这个函数运行在什么方法上。

所以,重点在于,在大多数情况下,这些位置之间的实际距离不会大于aprox,这对我来说会很有用。 100-200M?也许我应该检查Vincenty的公式?真的很慢吗?有人可以请我解释一下我应该选择什么? 不要使用distanceTo。使用distanceBetween方法,因为它听起来像你已经有了坐标,这就是你用这个方法所需要的全部:


i researched a little in this topic, but there are many opinions that don't exactly give a clear image. My problem is this: I'm developing a gps-based app for Android, in wich i want to know distance between my current location specified by Androids LocationManager, and other location in real time. I tried Haversine formula, a Law of Cosines formula, then I discovered, that Android SDK gives me a simple function Location.distanceTo(Location) - i'm not sure what method does this function runs on.
So, the point is, wich one will be good for me to use, in situations when real distance between these locations most of the time won't be larger than aprox. 100-200m? Maybe i should check Vincenty's formula? Is it realy that slow? Can someone please explain me what should I choose?

解决方案

Don't use distanceTo. Use the distanceBetween method as it sounds like you already have the coordinates and that's all you need with this method: Location.distanceBetween() Javadoc

这篇关于Android:计算两个位置之间距离的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:35