I have a database which contains many latitude and longitudes.
I need to get all the latitudes and longitudes sorted in ascending order by distance with respect to a latitude and longitude which I can set manually.
I used a formula to solve this problem which is:
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance
FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
37 and -122 are the latitudes and longitudes and it will return all the values in a field named distance in a sorted way.
My problem is that's not my necessity if a spot is 2 km away but driving distance is 11 km. I need a formula based on google maps which will calculate and return the driving distance between two coordinates.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…