Finding nearest distance between me and friends

555 Views Asked by At

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?

1

There are 1 best solutions below

4
On

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);

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