-3

我需要在android中找到位置数组列表的最近位置。现在我有了我当前的位置,我的意思是纬度、经度和一组朋友的位置。我需要找到离我最近的朋友?谁能建议我如何在android中做到这一点?

4

1 回答 1

0

使用位置类。它有一个方法调用distanceTo(Location loc)来计算两个位置之间的距离。

Location myLocation = new Location("LocProvider");
myLocation.setLatitude(latitude);
myLocation.setLongitude(longitude);

//Same as above, Setup friendLocation 

float distance = myLocation.distanceTo(friendLocation);

文档: http: //developer.android.com/reference/android/location/Location.html#distanceTo(android.location.Location)

于 2014-12-15T18:54:17.087 回答