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