How to calculate driving distance between two latitude and longitudes in PHP
<p>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:</p>

<pre><code>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 &lt; 25 ORDER BY distance LIMIT 0 , 20;
</code></pre>

<p>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&nbsp;km away but driving distance is 11&nbsp;km. I need a formula based on google maps which will calculate and return the driving distance between two coordinates.</p>