Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 两个位置之间的距离为';不对_Android_Maps_Distance_Haversine - Fatal编程技术网

Android 两个位置之间的距离为';不对

Android 两个位置之间的距离为';不对,android,maps,distance,haversine,Android,Maps,Distance,Haversine,我已经使用上的算法来计算两点之间的距离 我的两点是 long1 = 51.507467; lat1 = -0.08776; long2 = 51.508736; lat2 = -0.08612; 根据答案是0.1812公里 我的应用程序给出的结果(d)为0.230km 检查哈弗森公式: 您的实现是正确的。给定这些经纬度的距离应产生0.230 km。但是,坐标的正常输入是(纬度、经度)。将它们向后放置(经度、纬度)会产生不正确的距离0.1812 km为什么要重新发明自己的距离计算器,类中内置了

我已经使用上的算法来计算两点之间的距离

我的两点是

long1 = 51.507467;
lat1 = -0.08776;

long2 = 51.508736;
lat2 = -0.08612;
根据答案是0.1812公里

我的应用程序给出的结果(
d
)为0.230km

检查哈弗森公式:


您的实现是正确的。给定这些经纬度的距离应产生
0.230 km
。但是,坐标的正常输入是(纬度、经度)。将它们向后放置(经度、纬度)会产生不正确的距离
0.1812 km

为什么要重新发明自己的距离计算器,类中内置了一个

退房

distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) 
Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them.

Ally你的概念是对的。这行可能有点变化
double c=2*Math.asin(Math.sqrt(a))

哦。。。有点尴尬。谢谢你的帮助:)
distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) 
Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them.
public double CalculationByDistance(GeoPoint StartP, GeoPoint EndP) {  
  double lat1 = StartP.getLatitudeE6()/1E6;  
  double lat2 = EndP.getLatitudeE6()/1E6;  
  double lon1 = StartP.getLongitudeE6()/1E6;  
  double lon2 = EndP.getLongitudeE6()/1E6;  
  double dLat = Math.toRadians(lat2-lat1);  
  double dLon = Math.toRadians(lon2-lon1);  
  double a = Math.sin(dLat/2) * Math.sin(dLat/2) +  
     Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *  
     Math.sin(dLon/2) * Math.sin(dLon/2);  
  double c = 2 * Math.asin(Math.sqrt(a));  
  return Radius * c;  
 }