Check if the GPS location is within a certain radius of another GPS location in android

I am developing an Android application that takes the user's current location and shows the gps location of other users on a map that falls with a certain radius, say, 20 kilometers.

For example, if I am a user, I want to see the locations of other users on a map that are within a radius of 20 kilometers from my location.

I can save my location, the location of other users and map them. I cannot understand if these users are within a radius of 20 kilometers from my location or not.

I use the Google Maps Android v2 Android API to place locations on a map and Analysis to save GPS locations (latitude and longitude coordinates)

I googled for solutions, but in vain. Can someone provide a hint or link or sample code on how to check if the GPS location is within a certain radius of another GPS location or not.

Any help would be appreciated.

+5
source share
1 answer

It is very easy. When you add a marker to your map, simply move away from this marker to your current location if the distance is <= 20, then add this marker to the map. Thus

float[] results = new float[1]; Location.distanceBetween(oldPosition.latitude, oldPosition.longitude, newPosition.latitude, newPosition.longitude, results); 
+11
source

Source: https://habr.com/ru/post/1209229/


All Articles