-3

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?

user3675519
  • 11
  • 1
  • 9

1 Answers1

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

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

balachandarkm
  • 855
  • 2
  • 9
  • 11