谷歌地图距离矩阵API提供不可能短的duration_in_traffic结果,结果也不同于谷歌地图

问题描述 投票:-1回答:1

我正在向Google Maps Distance Matrix API请求获取今天下午两点之间的duration_in_traffic数据 - 伊斯坦布尔的Besiktas和Bosphorus Bridge-我将出发时间设置为2018年3月6日17:00:00。让我觉得它需要5分钟,这实际上是不可能的,应该至少需要20分钟。 Google地图中的结果也不同。

这是我使用的URL: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个回答
0
投票

您的出发时间以毫秒而不是秒为单位,这是Distance Matrix 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"
}
© www.soinside.com 2019 - 2024. All rights reserved.