Get Distance Between Two Location Points (GDBTLP)

I want to create an application that checks the nearest places where the user is. I can easily get the user's location and I already have a list of places with their respective coordinates (latitude and longitude).

What is the best way to find out the nearest places in a list to the user's current location.

I can't find anything on Google API.

Solution

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

https://developer.android.com/reference/android/location/Location#distanceTo(android.location.Location)

Post a Comment

Previous Next

نموذج الاتصال