Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travel Distance between two Lat and Long

I am looking to calculate and give the distance between two sets of Lat and Long for travel on Road.

I have had a look at the Google's Directions and Distance Matrix API. And also done a lot of other questions on SO.

But i am not able to figure out the best possible way to do it, you need to calculate the distance to around 20-25 locations at each time.

We are building a travel app that requires this information for the user on Android device from where he is.

like image 200
Harsha M V Avatar asked Jan 29 '13 17:01

Harsha M V


1 Answers

If You are looking for driving distance NOT shortest distance then You can try to call API service with URL like:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=54.406505,18.67708&destinations=54.446251,18.570993&mode=driving&language=en-EN&sensor=false

This will result in JSON like this:

{
   "destination_addresses" : [ "Powstańców Warszawy 8, Sopot, Polska" ],
   "origin_addresses" : [ "majora Henryka Sucharskiego 69, Gdańsk, Polska" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "24,7 km",
                  "value" : 24653
               },
               "duration" : {
                  "text" : "34 min",
                  "value" : 2062
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

Result distance is actual road distance between two locations.

You can find more details in The Google Distance Matrix API

like image 142
rumburak Avatar answered Sep 19 '22 13:09

rumburak