Android 计算从一个GPS坐标到另一个GPS坐标的距离?
我正在尝试创建一个Android应用程序,每移动2米,它就会更新我的位置。我使用的Api是:Android 计算从一个GPS坐标到另一个GPS坐标的距离?,android,gps,geolocation,Android,Gps,Geolocation,我正在尝试创建一个Android应用程序,每移动2米,它就会更新我的位置。我使用的Api是: lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, (float)2, locationListener); 我能用哈弗公式计算两个坐标之间的距离。 我想知道我在横向和纵向移动了多少距离。 我的意思是,我想知道以前位置的delta(x)和delta(y),单位为米。我随身带着currentLat,currentLong,previ
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, (float)2, locationListener);
我能用哈弗公式计算两个坐标之间的距离。我想知道我在横向和纵向移动了多少距离。 我的意思是,我想知道以前位置的
delta(x)
和delta(y)
,单位为米。我随身带着currentLat
,currentLong
,previousLat
,previousLong
例如:我在我的应用程序中获得以下GPS坐标:Latitude: 12.9812007 Longitude: 77.74348163
Latitude: 12.98119122 Longitude: 77.74348192
Latitude: 12.98118058 Longitude: 77.74348131
Latitude: 12.9812041 Longitude: 77.74350371
Latitude: 12.98119337 Longitude: 77.74350154
Latitude: 12.98117935 Longitude: 77.74350156
Latitude: 12.9811742 Longitude: 77.74349111
Latitude: 12.98116478 Longitude: 77.74348577
Latitude: 12.98114454 Longitude: 77.7434776
Latitude: 12.98113244 Longitude: 77.74347141
Latitude: 12.98112247 Longitude: 77.74346629
Latitude: 12.98111381 Longitude: 77.74347568<br/>
Latitude: 12.98112889 Longitude: 77.74348118
Latitude: 12.9811384 Longitude: 77.74348133
Latitude: 12.98114325 Longitude: 77.74346866
Latitude: 12.9811306 Longitude: 77.74345533
Latitude: 12.98112043 Longitude: 77.74344925
Latitude: 12.98110867 Longitude: 77.74344979
Latitude: 12.98109571 Longitude: 77.74345256
Latitude: 12.98110153 Longitude: 77.74346184
Latitude: 12.98111135 Longitude: 77.74346482
Latitude: 12.98112283 Longitude: 77.74346764
Latitude: 12.98113165 Longitude: 77.74347133
Latitude: 12.98114311 Longitude: 77.74347645
Latitude: 12.98115332 Longitude: 77.74348057
纬度:12.9812007经度:77.74348163
纬度:12.98119122经度:77.74348192
纬度:12.98118058经度:77.74348131
纬度:12.9812041经度:77.74350371
纬度:12.98119337经度:77.74350154
纬度:12.98117935经度:77.74350156
纬度:12.9811742经度:77.74349111
纬度:12.98116478经度:77.74348577
纬度:12.98114454经度:77.7434776
纬度:12.98113244经度:77.74347141
纬度:12.98112247经度:77.74346629
纬度:12.98111381经度:77.74347568
纬度:12.98112889经度:77.74348118
纬度:12.9811384经度:77.74348133
纬度:12.98114325经度:77.74346866
纬度:12.9811306经度:77.74345533
纬度:12.98112043经度:77.74344925
纬度:12.98110867经度:77.74344979
纬度:12.98109571经度:77.74345256
纬度:12.98110153经度:77.74346184
纬度:12.98111135经度:77.74346482
纬度:12.98112283经度:77.74346764
纬度:12.98113165经度:77.74347133
纬度:12.98114311经度:77.74347645
纬度:12.98115332经度:77.74348057
如果您想分别了解两个位置之间的纬度差和纵向差,则应尝试下面给出的解决方案
如果你有
currentLat = 12.98119122 currentLong = 77.74348192
及
然后要查找latDifference
use
haversine(double currentLat, double previousLong, double previousLat, double previousLong)
haversine(double previousLat, double currentLong, double previousLat, double previousLong)
这将为您提供两个位置之间的纬度差异,并找到longDifference
use
haversine(double currentLat, double previousLong, double previousLat, double previousLong)
haversine(double previousLat, double currentLong, double previousLat, double previousLong)
我想你们知道哈弗森公式,正如你们在问题中所说的
编辑:
若要查找经度差异,请对当前经度和上一经度使用相同的值
要找到长差,请在哈弗森公式中对当前纬度和先前纬度使用相同的值。问题是什么?将此作为注释,因为这只是一个解决方法:如果您设置了一个计算实际距离的好方法,请继续使用它来获得所需的距离,对于您的delta(x)传递,0中的2长。。。对于0….的2个板条中的增量(y)焊道。。。。为了它的价值…;-)