这里是找到两个位置之间的距离的完整方法,只需要两个lats longs作为参数,它将返回字符串中的距离。
public static String distFrom(double current_lat, double current_long, double latst, double longst) {
double earthRadius = 3958.75;
double dLat = Math.toRadians(latst-current_lat);
double dLng = Math.toRadians(longst-current_long);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(Math.toRadians(lat)) * Math.cos(Math.toRadians(latst)) * Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
double meterConversion = 1.609344; //Kilometer
//for two digits float value:
String s = String.format("%.2f", (dist * meterConversion));
return s;
}
返回距离是千米可以将其进一步隐蔽到英里
可以查找[haversine公式(https://en.wikipedia.org/wiki/Haversine_formula)来计算两点之间的实际距离。然后检查是否添加了“result =
KarelG
hii @David你有没有找到任何好的解决方案,我喜欢你的问题,我想要这样的东西..你能详细解释你的问题,还有一些代码!? –