I need to find nearest location of arraylist of location in android.now i have my current location i mean latitude,longitude and set of friends locations. i need to find which friend is nearest to me? can anyone suggest me the way how to do this in android?
Asked
Active
Viewed 521 times
1 Answers
0
Use Location class. It has a method called distanceTo(Location loc)
to calculate the distance between two Locations.
Location myLocation = new Location("LocProvider");
myLocation.setLatitude(latitude);
myLocation.setLongitude(longitude);
//Same as above, Setup friendLocation
float distance = myLocation.distanceTo(friendLocation);

balachandarkm
- 855
- 2
- 9
- 11
-
comparing with set of my friends location – user3675519 Dec 15 '14 at 19:16
-
repeat the logic in a loop against all your friend locations and find the shortest distance to get the friend who is close to you. – balachandarkm Dec 15 '14 at 19:18
-
can you give sample code – user3675519 Dec 15 '14 at 19:20
-
Just iterate the set and find the shortest! – balachandarkm Dec 15 '14 at 19:25