【问题标题】:Google Maps Distance Matrix API gives impossibly short duration_in_traffic results and also the results are different than Google MapsGoogle Maps Distance Matrix API 提供了难以置信的短 duration_in_traffic 结果,而且结果与 Google Maps 不同
【发布时间】:2018-08-14 06:11:37
【问题描述】:

我正在向 Google Maps Distance Matrix API 发出请求,以获取今天下午在伊斯坦布尔的两点 - 贝西克塔斯和博斯普鲁斯海峡大桥 - 之间的 duration_in_traffic 数据,我已将出发时间设置为 3 月 6 日的 17:00:00 2018。它告诉我这需要 5 分钟,这实际上是不可能的,应该至少 20 分钟。谷歌地图中的结果也不同。

这是我使用的网址: https://maps.googleapis.com/maps/api/distancematrix/json?&departure_time=1520301600000&traffic_model=pessimistic&origins=41.045524,29.007519&destinations=41.050044,29.029765&key=MYKEY

这是 JSON 响应:

    {
   "destination_addresses" : [
      "Ortaköy Mh., İstanbul Çevre Yolu, 34347 Beşiktaş/İstanbul, Turkey"
   ],
   "origin_addresses" : [
      "Cihannüma Mahallesi, Barbaros Blv. No:76, 34353 Beşiktaş/İstanbul, Turkey"
   ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "3.1 km",
                  "value" : 3052
               },
               "duration" : {
                  "text" : "4 mins",
                  "value" : 217
               },
               "duration_in_traffic" : {
                  "text" : "5 mins",
                  "value" : 295
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

Here's the Google Maps Screenshot for the specified time and destination

我不知道是什么原因造成的,但如果您能提供帮助,我将不胜感激。

【问题讨论】:

    标签: google-maps google-maps-api-3 google-api google-distancematrix-api distance-matrix


    【解决方案1】:

    您的出发时间以毫秒而不是秒为单位,这是距离矩阵 API 所用的时间

    https://developers.google.com/maps/documentation/distance-matrix/intro#departure-time

    departure_time — 期望的出发时间。您可以将时间指定为自 UTC 1970 年 1 月 1 日午夜开始的 整数。或者,您可以指定 now 的值,将出发时间设置为当前时间(精确到最接近的秒数)。

    此外,将出发时间转换为秒数 1520301600 后,日期实际上是 2018 年 3 月 6 日 0200 UTC,即当地时间上午 5 点,而不是下午 5 点。使用 1520517600,对应当地时间 2018 年 3 月 8 日下午 5 点,duration_in_traffic 为 18 分钟:

    https://maps.googleapis.com/maps/api/distancematrix/json?departure_time=1520517600&traffic_model=pessimistic&origins=41.045524,29.007519&destinations=41.050044,29.029765&key=YOUR_KEY

    {
       "destination_addresses" : [
          "Ortaköy Mh., İstanbul Çevre Yolu, 34347 Beşiktaş/İstanbul, Turkey"
       ],
       "origin_addresses" : [
          "Cihannüma Mahallesi, Barbaros Blv. No:76, 34353 Beşiktaş/İstanbul, Turkey"
       ],
       "rows" : [
          {
             "elements" : [
                {
                   "distance" : {
                      "text" : "3.1 km",
                      "value" : 3052
                   },
                   "duration" : {
                      "text" : "4 mins",
                      "value" : 217
                   },
                   "duration_in_traffic" : {
                      "text" : "18 mins",
                      "value" : 1081
                   },
                   "status" : "OK"
                }
             ]
          }
       ],
       "status" : "OK"
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-08
      • 2014-02-18
      • 2019-01-05
      • 2017-08-05
      • 2018-03-28
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多