-4

I have longtitude and lattitude of a GPS location of user in an application android. And I have to store other GPS location in postgresql database(now i haven't had idea for storing). Now I want to check user is that location or not by sending location from android to server using Spring boot? What should I do now? Please give me some advices. Thanks a lot.

Mart
  • 13
  • 1
  • 7
  • I searched a lot but did not match my problem. If you downvote, please give me the reason. thanks – Mart Apr 14 '19 at 03:39

1 Answers1

0

You can fetch the location from the server using an API call and compare the coordinates with the current location using Location.distanceTo(android.location.Location)

//fetch location from server
double lon = 12.227458, lat = 22.456545;

//create new location instance with fetched coordinates
Location locationFromServer = new Location();
locationFromServer.setLongitude(lon);
locationFromServer.setLatitude(lat);

//some method returns the current location
Location current = getCurrentLocation();

//compare locations
double distance = current.distanceTo(locationFromServer);

//do whatever you want with distance...

Hope this helps!

Lakshan Dissanayake
  • 521
  • 1
  • 4
  • 18