0

I've an Android App where I take the GPS position, and I have a back-end REST service written in Laravel, and in my DB I have a table named 'GPS' which saves the GPS coordinates when I click on a 'Save' button.

When I click on the 'Save' button on My app, it must check whether the current position is within a radius of X meters when compared to one of the saved GPS on my DB.

I have no idea on doing it, is it possible?

Table GPS field are:
id, gps

Krishna Chandran
  • 389
  • 3
  • 18
LorenzoBerti
  • 6,704
  • 8
  • 47
  • 89

2 Answers2

1

Depends on how your GPS column looks like but you can easily calculate the distance from two gps (lat, lng) points with the haversine formula.

See this nice explanation in Javascript: http://www.movable-type.co.uk/scripts/latlong.html

Basically, you calculate the distance between your two points and then check if the result is within your radius.

For PHP, just search stackoverflow. For calculation with MySQL, take a look at this answer.

Community
  • 1
  • 1
wiesson
  • 6,544
  • 5
  • 40
  • 68
  • Thank you! my field is a simple varchar where lat and lng are divided by comma ex. 43.8465317,10.4364944 I will see link and come back :) ! thanks – LorenzoBerti Aug 10 '16 at 08:59
  • I would recommend to split the field into two db columns to calculate the distance with a database query. So instead of "gps" add gps_latitude and gps_longitude. :) – wiesson Aug 10 '16 at 09:03
-1

I have a plan for it:
1. create new route
2. create controller or use exist
3. create action
4. create function for search these points in your DB
5. provide it in JSON or XML format

Just use it from point to point.

Michail M.
  • 735
  • 5
  • 11