Android我怎么能找到Java代码两点之间的距离? 3 月,1 周 Questions & Answers 266 我有两点的lat和lan。 如何计算这两点之间的距离? 如果你有任何代码或链接,那么请建议我 多谢各位
# 1 楼答案 试试这个,你会走得更远 private String distance(double lati, double longi, double curlati1, double curlongi1) { double theta = longi - curlongi1; double dist = Math.sin(deg2rad(lati)) * Math.sin(deg2rad(curlati1)) + Math.cos(deg2rad(lati)) * Math.cos(deg2rad(curlati1)) * Math.cos(deg2rad(theta)); dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; dist = dist * 1.609344; result = Double.toString(dist); System.out.println("dist_result :" + result); return (result); } /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ /* :: This function converts decimal degrees to radians : */ /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ private double deg2rad(double deg) { return (deg * Math.PI / 180.0); } /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ /* :: This function converts radians to decimal degrees : */ /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ private double rad2deg(double rad) { return (rad * 180.0 / Math.PI); }
# 2 楼答案 您可以使用Android SDK函数distanceBetween Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.
# 1 楼答案
试试这个,你会走得更远
# 2 楼答案
您可以使用Android SDK函数distanceBetween