Sun*_*nny 64 android location distance latitude-longitude
请详细说明这种情况
现在我有两个阵列有附近地区的纬度和经度,也有用户位置latiude和longiude现在我想计算用户位置和附近的地方之间的距离,并希望在列表视图中显示它们.
我知道有一种计算距离的方法
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results);
Run Code Online (Sandbox Code Playgroud)
现在问题是如何在这个方法中传递这两个具有近纬度和长度的阵列并获得距离数组.
Kar*_*thi 170
http://developer.android.com/reference/android/location/Location.html
查看distanceTo或distanceBetween.您可以从纬度和经度创建Location对象:
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);
Run Code Online (Sandbox Code Playgroud)
要么
private double meterDistanceBetweenPoints(float lat_a, float lng_a, float lat_b, float lng_b) {
float pk = (float) (180.f/Math.PI);
float a1 = lat_a / pk;
float a2 = lng_a / pk;
float b1 = lat_b / pk;
float b2 = lng_b / pk;
double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
double t3 = Math.sin(a1) * Math.sin(b1);
double tt = Math.acos(t1 + t2 + t3);
return 6366000 * tt;
}
Run Code Online (Sandbox Code Playgroud)
san*_*ram 15
试试此代码.这里我们有两个经度和纬度值和selected_location.distanceTo(near_locations)函数返回这些位置之间的距离(米).
Location selected_location=new Location("locationA");
selected_location.setLatitude(17.372102);
selected_location.setLongitude(78.484196);
Location near_locations=new Location("locationB");
near_locations.setLatitude(17.375775);
near_locations.setLongitude(78.469218);
double distance=selected_location.distanceTo(near_locations);
Run Code Online (Sandbox Code Playgroud)
这里"距离"是locationA和locationB之间的距离(以米为单位)
| 归档时间: |
|
| 查看次数: |
126833 次 |
| 最近记录: |