两个地理地点之间的距离计算 [英] Calculating distance between two geographic locations

查看:640
本文介绍了两个地理地点之间的距离计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请阐明这种情况下一些轻

please shed some light on this situation

现在,我已经有纬度附近的地方和经度2阵,也有用户位置latiude和longiude现在我想计算出用户的位置和附近的地点之间的距离,并希望将其显示在列表视图。

Right now i have two array having latitude and longitude of nearby places and also have the user location latiude and longiude now i want to calculate the distance between user location and nearby places and want to show them in listview.

我知道,有计算距离,

public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results);

现在有什么问题是如何通过这两个阵列,有附近的纬度和longitue在这种方法中,并得到距离的数组。

Now what is the problem is how to pass these two array having nearby latitude and longitue in this method and get the array of distances.

推荐答案

<一个href="http://developer.android.com/reference/android/location/Location.html">http://developer.android.com/reference/android/location/Location.html

。看看distanceTo或distanceBetween。您可以从一个纬度和经度位置的对象:

Look into distanceTo or distanceBetween. You can create a Location object from a latitude and longitude:

Location locationA = new Location("point A");

locationA.setLatitude(latA);
locationA.setLongitude(lngA);

Location locationB = new Location("point B");

locationB.setLatitude(latB);
locationB.setLongitude(lngB);

float distance = locationA.distanceTo(locationB);

private double gps2m(float lat_a, float lng_a, float lat_b, float lng_b) {
    float pk = (float) (180/3.14169);

    float a1 = lat_a / pk;
    float a2 = lng_a / pk;
    float b1 = lat_b / pk;
    float b2 = lng_b / pk;

    float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2);
    float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2);
    float t3 = FloatMath.sin(a1)*FloatMath.sin(b1);
    double tt = Math.acos(t1 + t2 + t3);

    return 6366000*tt;
}

这篇关于两个地理地点之间的距离计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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