Compare geopoints with user geolocation

Asked

Viewed 471 times

1

I’m using the Google Maps API v2 in the Android Studio and I took the base code that made it available and just implemented a few points on the map, using latitude and longitude of the points (mMap.addMarker). I also added the feature 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 have some function in the API itself to do this?

If not, what would be an alternative?

1 answer

4

To calculate the distance, in meters, between two coordinates can use the class Sphericalutil of Google Maps Android API Utility Library.

Add the following application Gradle dependency:

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

To calculate the distance use:

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

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

  • excellent answer..... by the way, it’s from Armada?

  • @Luisa Almeida, yes I am.

  • I’m from America.... :)

  • @Luisa Almeida good luck. :)

  • I’ll use this one, but first I need a function that returns the user’s coordinates so... Because I am using "mmap.setMyLocationEnabled(true);", which is a function available direct from Google Maps API v2, this function returns the user’s location as a blue dot on the map, but does not return the coordinates...

  • That’s another question, look at this reply

  • Thank you very much, this answer mentioned uses a function that is in disuse (deprecated), but for her, I was able to find the function currently used by Google Maps API, here is the link for future interested (I do not know use the link tool kk): http://stackoverflow.com/questions/23104089/googlemap-getmylocation-cannot-get-current-location

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.