Compare geopoints with user geolocation

1

I'm using Google Maps API v2 in Android Studio and picked up the base code as available and only implemented a few points on the map, using latitude and longitude of points (% w / w). I also added the function to locate the user on the map. Now I need the application to point out which of these points is closest to the user.

Would you have some function in the API itself to do this?

If not, what would be an alternative?

    
asked by anonymous 06.10.2016 / 04:12

1 answer

4

To calculate the distance in meters between two coordinates you can use the SphericalUtil class of < a href="https://developers.google.com/maps/documentation/android-api/utility/"> Google Maps Android API Utility Library .

Add the following dependency to the application Gradle:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}

To calculate distance use:

double distancia = SphericalUtil.computeDistanceBetween(LatLng from, LatLng to);

Note that the calculated distance is on the surface of the earth and not by road.

    
06.10.2016 / 13:21