如何找到在图2 geopoints之间的正确距离?正确、距离、geopoints

2023-09-05 01:00:54 作者:夏目友人赖帐

我需要开发的应用程序,其中用户找到他的车,他已经停止,并显示距离他和车载parked.I使用GPS和位置服务的。

I need to develop app where user has to locate his car that he has parked and show distance between him and car parked.I used GPS and location services.

有关的距离,我用的半正矢公式,但距离始终显示为0米。

For distance i used haversine formula but the distance always shows 0 meters.

我尝试了很多寻找解决方案,谷歌,但力得到任何正确的解决方案。

I tried a lot searching for solution in google but dint get any correct solution.

谁能给他们的建议?

推荐答案

谷歌文档有两种方法

如果您是从的GeoPoint越来越纬度/经度,然后他们在microdegrees。您必须通过1e6个繁殖。

If you are getting lat/lon from GeoPoint then they are in microdegrees. You must multiply by 1e6.

但是我preferred使用下面的方法。 (其基于半正矢公式上)

http://www.$c$c$c$cx.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;
}

最后,我想与大家分享奖金的信息。

At last i would like to share bonus information.

如果您正在寻找行车路线,两个地点之间的路线然后前往

http://$c$c.google.com/p/j2memaprouteprovider/