Travel Distance between two Lat and Long

前端 未结 3 469
故里飘歌
故里飘歌 2021-02-06 05:34

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 A

3条回答
  •  野性不改
    2021-02-06 06:26

    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

提交回复
热议问题