且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在php中计算两个邮政编码之间的距离

更新时间:2023-02-01 22:50:57

If you take a look at the result from google you will notice that it is calculating a route from india to russia.

"destination_addresses" : [ "Wologda, Oblast Wologda, Russland, 160017" ],
"origin_addresses" : [ "Punjab 144216, Indien" ],

This happens because you only provided postal codes, without reference from which country they are. I assume you want to calculate a route within india, since your profile shows that you are from there.

If you just add ,india to your postal codes, like this:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=144216,india&destinations=160017,india&mode=driving&language=en-EN&sensor=false

You get a result that looks much more like what you want:

{
   "destination_addresses" : [ "Chandigarh, 160017, India" ],
   "origin_addresses" : [ "Punjab 144216, India" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "201 km",
                  "value" : 200693
               },
               "duration" : {
                  "text" : "3 hours 30 mins",
                  "value" : 12625
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}