0

I have a GPS coordinate Lat 4.649182 Long -74.108948 in a table "A", I need to calculate distances with values ​​stored in a table "B" like this:

Id    UserID  Lat             Long       
1     1       4.649200    -74.109200 
2     1       4.649110    -74.108860 
3     2       4.648985    -74.108831 
4     3       4.64923     -74.10893666

Normally use this formula to calculate the distance between two points:

SELECT (acos(sin(radians(LATITUDE_1)) * sin(radians(LATITUDE_2)) +
cos(radians(LATITUDE_1)) * cos(radians(LATITUDE_2)) * 
cos(radians(LONGITUDE_1) - radians(LONGITUDE_2))) * 6378) as Distance;

But I need the result shows the distance between various points when the UserID = 1 and it looks like this

Id    UserID  Lat             Long       Distance
1     1       4.649200    -74.109200      XX
2     1       4.649110    -74.108860      XX
Javier
  • 99
  • 1
  • 9
  • Do you mean to compare all points associated with User 1 with all points defined by other users? – tadman Oct 25 '12 at 22:34
  • Yes the value 4.649182 Lat -74.108948 Long is stored in a table "A" and the other values ​​that I calculate are in Table "B" – Javier Oct 25 '12 at 22:39
  • This doesn't look like a typical distance calculation. Haversine method is more usual... See http://stackoverflow.com/questions/365826/calculate-distance-between-2-gps-coordinates – paddy Oct 25 '12 at 22:40

0 Answers0