【发布时间】:2014-07-12 15:03:22
【问题描述】:
我使用这个获得了两个位置:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
然后我计算它们之间的距离,但距离不正确
public static float calculateDistance(double e, double f, double g, double h)
{
float dLat = (float) Math.toRadians(g - e);
float dLon = (float) Math.toRadians(h - f);
float a =
(float) (Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(e))
* Math.cos(Math.toRadians(g)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
float d = 6371 * c;
return d;
}
(32.2163799,35.0420986) (31.9210915,35.2037014)
结果 36.193707 公里 但实际远不止这些,大约 85 公里
【问题讨论】:
-
你怎么知道diszance不是真的?你从哪里得到的 85 公里?您是否通过允许计算距离的网页检查了距离?