如何比较2个位置的位置 [英] How to compare 2 location positions

查看:195
本文介绍了如何比较2个位置的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 TextView 的应用程序,可以找到您的位置,当您移动时, TextView 中的值会发生变化。

我想知道我能做什么才能注册第一个位置,然后在5分钟后查找位置。



例如:

分钟0

LAT 000000

LONG 000000



(SAVE IT)



分钟5 < br>
LAT 1111111

LONG 111111



if min0 == min 5 strong>



...



总结一下,我想比较一下2个字符串(开始处的lat& long)和lat&



任何建议将不胜感激。

解决方案

此链接应符合您的目的;



浏览 distanceTo或distanceBetween 。您可以根据经纬度创建Location对象:

 位置位置=新位置(); 
location.setLatitude(lat);
location.setLongitude(lon);

我遇到的另一个解决方案

有一个标准公式( Haversine (也就是说,它适用于任何地球上的经度/纬度),但由于需要7个三角和2个平方根,因此性能较差。

如果你的几个点不太相隔,你可以使用近似版本( Equirectangular ),这个速度要快得多。 / p>

  //近似Equirectangular  - 如果(lat1,lon1)〜(lat2,lon2)
double x =( lon2 - lon1)* Math.cos((lat1 + lat2)/ 2);
double y =(lat2 - lat1);
double d = Math.sqrt(x * x + y * y)* R; //其中R是地球的半径
// R是6,371 km

希望有帮助。


I have an App with a TextView that finds your location and when you move, the value in TextView changes.

I want to know what can I do in order to register the first location and then look for the location 5 min after.

For example:

min 0
LAT 000000
LONG 000000

( SAVE IT )

min 5
LAT 1111111
LONG 111111

if min0 == min 5

...

To sum up, I want to compare 2 strings (lat & long at the beginning) and lat & long after 5 minutes.

Any suggestion will be appreciated.

解决方案

This Link should serve your purpose;

Go through distanceTo or distanceBetween. You can create a Location object from a latitude and longitude:

Location location = new Location("");
location.setLatitude(lat);
location.setLongitude(lon);

Another Solution I came across,

There is a standard formula (Haversine) (that is, it works for any couple of longitude/latitude on earth) but the performance is slow as it needs 7 trigonometric and 2 square roots.

If your couple of points are not too far apart, you can use an approximate version (Equirectangular), which is much faster.

// Approximate Equirectangular -- works if (lat1,lon1) ~ (lat2,lon2)
double x = (lon2 - lon1) * Math.cos((lat1 + lat2) / 2);
double y = (lat2 - lat1);
double d = Math.sqrt(x * x + y * y) * R; // where R is the earth's Radius
                                         // R is 6,371 km

Hope that helps.

这篇关于如何比较2个位置的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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