問題描述
流量中的 Google Maps Distance Matrix API 持續時間添加返回錯誤結果的所有段 (Google Maps Distance Matrix API duration in traffic adding all segments returning wrong result)
我在 Google 地圖上的一條道路上連續設置了 11 個點當我計算在相鄰點之間行駛所需的時間並將它們相加時,總結果與從第一個點和最後一個點之間行駛所需的時間不同點
ie
A ‑> B
B ‑> C
C ‑> D
is not equal to
A ‑> D
誰能舉例說明為什麼會這樣。
參考解法
方法 1:
Here is the example: I have some coordinates
`
p1=(49.338202, ‑123.142030)
p2=(49.335271, ‑123.125171)
p3=(49.332503, ‑123.116240)
p4=(49.332447, ‑123.104249)
p5=(49.331949, ‑123.092218)
p6=(49.331996, ‑123.077877)
p7=(49.329556, ‑123.054275)
p8=(49.326069, ‑123.048102)
p9=(49.312711, ‑123.030485)
p10=(49.306328, ‑123.028022)
p11=(49.291653, ‑123.026348)
directions_results1 = gmaps.distance_matrix(p1,p2,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results2 = gmaps.distance_matrix(p2,p3,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results3 = gmaps.distance_matrix(p3,p4,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results4 = gmaps.distance_matrix(p4,p5,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results5 = gmaps.distance_matrix(p5,p6,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results6 = gmaps.distance_matrix(p6,p7,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results7 = gmaps.distance_matrix(p7,p8,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results8 = gmaps.distance_matrix(p8,p9,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results9 = gmaps.distance_matrix(p9,p10,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results10 = gmaps.distance_matrix(p10,p11,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_resultst = gmaps.distance_matrix(p1,p11,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
the number is in second
Output
Segment 1 Time: 149
Segment 2 Time: 37
Segment 3 Time: 63
Segment 4 Time: 49
Segment 5 Time: 49
Segment 6 Time: 96
Segment 7 Time: 35
Segment 8 Time: 141
Segment 9 Time: 134
Segment 10 Time: 134
Sum of Time required for all Segments: 887
Time required from First point to Last point: 1084
`