如何找到在图2 geopoints之间的正确距离? [英] how to find the correct distance between two geopoints in map?

查看:201
本文介绍了如何找到在图2 geopoints之间的正确距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发的应用程序,其中用户找到他的车,他已经停止,并显示距离他和车载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使用下面的方法。 (其基于半正矢公式上)

<一个href="http://www.$c$c$c$cx.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe">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.

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

<一个href="http://$c$c.google.com/p/j2memaprouteprovider/">http://$c$c.google.com/p/j2memaprouteprovider/

这篇关于如何找到在图2 geopoints之间的正确距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆