Get the distance between two geo points

Chmouel Boudjnah picture Chmouel Boudjnah · Apr 30, 2010 · Viewed 150.2k times · Source

I want to make an app which checks the nearest place where a user is. I can easily get the location of the user and I have already a list of places with latitude and longitude.

What would be the best way to know the nearest place of the list against the current user location.

I could not find anything in the google APIs.

Answer

praveen picture praveen · Dec 15, 2013
Location loc1 = new Location("");
loc1.setLatitude(lat1);
loc1.setLongitude(lon1);

Location loc2 = new Location("");
loc2.setLatitude(lat2);
loc2.setLongitude(lon2);

float distanceInMeters = loc1.distanceTo(loc2);

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