Google Documents có hai phương pháp
Nếu bạn đang nhận được lat/lon từ GeoPoint sau đó họ đang có trong microdegrees. Bạn phải nhân với 1e6.
Nhưng tôi thích sử dụng phương thức bên dưới. (Dựa trên Haversine Formula)
http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe
double dist = GeoUtils.distanceKm(mylat, mylon, lat, lon);
/**
* Computes the distance in kilometers between two points on Earth.
*
* @param lat1 Latitude of the first point
* @param lon1 Longitude of the first point
* @param lat2 Latitude of the second point
* @param lon2 Longitude of the second point
* @return Distance between the two points in kilometers.
*/
public static double distanceKm(double lat1, double lon1, double lat2, double lon2) {
int EARTH_RADIUS_KM = 6371;
double lat1Rad = Math.toRadians(lat1);
double lat2Rad = Math.toRadians(lat2);
double deltaLonRad = Math.toRadians(lon2 - lon1);
return Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad) + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM;
}
Cuối cùng tôi muốn chia sẻ thông tin tiền thưởng.
Nếu bạn đang tìm kiếm đường lái xe, tuyến đường giữa hai địa điểm sau đó đi đến
http://code.google.com/p/j2memaprouteprovider/
Nguồn
2012-07-02 13:03:16
bản sao của http://stackoverflow.com/questions/2741403/get-the-distance-between-two-geo- điểm – logcat
Đọc tất cả câu trả lời của Câu hỏi này http://stackoverflow.com/questions/7696112/gettting-different-distance-when-using-the-google-map-and-user-defined-function/7752341#7752341 – MKJParekh
xem câu hỏi [ở đây] (http://stackoverflow.com/questions/19218081/how-to-calculate-distance-from-different-markers-in-a-map-and-then-pick-up-the-l) . Điều này có câu trả lời tương tự với nhiều phép tính khoảng cách. Xem câu trả lời được chấp nhận. – Akshat