Find estimated Time & distance between two points using latitude and longitude in mysql

Viewed 36

Hi I have the following table


--------------------------------------------
|  id  |  city  |  Latitude  |  Longitude  |
--------------------------------------------
|  1   |   3    |   34.44444 |   84.3434   |
--------------------------------------------
|  2   |   4    | 42.4666667 | 1.4666667   |
--------------------------------------------
|  3   |   5    |  32.534167 | 66.078056   |
--------------------------------------------
|  4   |   6    |  36.948889 | 66.328611   |
--------------------------------------------
|  5   |   7    |  35.088056 | 69.046389   |
--------------------------------------------
|  6   |   8    |  36.083056 |   69.0525   |
--------------------------------------------
|  7   |   9    |  31.015833 | 61.860278   |

Now I want to get estimated Time & Distance between two points. Say a user is having a city 3 and a user is having a city 7. My scenario is one user having a city and latitue and longtitude is searching other users estimated Time & Distance from his city. For example user having city 3 is searching. He wants to get distance of user of any other city say it is 7. I have searched and found following query and only get distance but i need distance and estimated arrival time

   111.111 *
    DEGREES(ACOS(LEAST(1.0, COS(RADIANS(a.Latitude))
         * COS(RADIANS(b.Latitude))
         * COS(RADIANS(a.Longitude - b.Longitude))
         + SIN(RADIANS(a.Latitude))
         * SIN(RADIANS(b.Latitude))))) AS distance_in_km
  FROM city AS a
  JOIN city AS b ON a.id <> b.id
 WHERE a.city = 3 AND b.city = 7 ```
0 Answers
Related