Google 路线 API 中转 returns 总是 "ZERO_RESULTS"
Google Directions API transit returns always "ZERO_RESULTS"
我正在开发一个应用程序,该应用程序使用 google API 获取交通解决方案以在所需时间到达某个位置。
我调用 google API 的代码与 "driving" 和 "walking" 旅行模式完美配合,但与 "transit" 和 "bicycling"响应始终标记为状态 "ZERO_RESULTS" 并且不计算任何路由。
根据 google 文档,这意味着在必须计算解决方案的国家/地区不提供公共交通和骑自行车。
我尝试了几个国家,我总是得到相同的结果,我也尝试了概述中的 Google 示例(用于过境),但它不起作用。
我通过HTTPS请求传递的参数是:出发地、目的地、出行方式,arrival_time。
我尝试的第一件事是更改 arrival_time,以防该值引用过去或太遥远的未来,但它不起作用。
万一我没有通过 "arrival_time" 响应是完美的,但我不明白,因为在 Google 文档中很清楚 arrival_time 是一个可能的参数https 请求也带有过境旅行模式。没有这个论点,请求对我的目标是无用的。
奇怪的是,如果我通过 "transit"(到达或离开时间),响应是这样的:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
如果我传递 "bicycling"(所有其他参数不变):
{
"available_travel_modes" : [ "DRIVING", "WALKING", "TRANSIT" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
所以在第二种情况下 API 说 TRANSIT 可用,这根本没有意义!
我使用的位置格式是地理坐标,以避免出现歧义。
希望我能提供足够的信息让你能够帮助我。
编辑:抱歉,我认为我的 post 已经足够清楚了。
我使用 Google 方向 API: https://developers.google.com/maps/documentation/directions/
我的问题是 "transit" 和 "bicycling" 作为旅行模式,不是代码问题,但问题出现在 https 响应级别,即使使用 google 示例也是如此对于可以在概述中找到的 "transit",我获得了 "ZERO_RESULTS" 响应。
这是示例的URL:
https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&mode=transit&arrival_time=1391374800&key=YOUR_API_KEY
下面是两个 URL,它们让我得到了我在上面复制的两个回复:
有中转:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
骑自行车:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
在我用于起点和终点地理坐标的代码中,如下所示:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=transit&arrival_time=1513162800000&key=++API_KEY++
唯一的区别是 google 不识别地理编码 waypoints:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [ {}, {} ],
"routes" : [],
"status" : "ZERO_RESULTS"
}
如果我使用 "driving" 作为旅行模式,这有效:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=driving&arrival_time=1513162800000&key=++API_KEY++
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJC5u9LazGhkcRXAZQFNDTpKc",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4731019,
"lng" : 12.6177051
},
"southwest" : {
"lat" : 41.9028523,
"lng" : 9.1839517
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "573 km",
"value" : 572600
},
"duration" : {
"text" : "5 ore 51 min",
"value" : 21069
},
"end_address" : "Via Silvio Pellico, 2, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"steps" : [
{
"distance" : {
"text" : "93 m",
"value" : 93
},
"duration" : {
"text" : "1 min",
"value" : 19
},
"end_location" : {
"lat" : 41.9035781,
"lng" : 12.4959908
},
"html_instructions" : "Procedi in direzione \u003cb\u003enord\u003c/b\u003e da \u003cb\u003ePiazza della Repubblica\u003c/b\u003e verso \u003cb\u003eVia Giuseppe Romita\u003c/b\u003e",
"polyline" : {
"points" : "ycw~F}ugkAU?I@E@E@a@RG@EDED_@d@OP"
},
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"travel_mode" : "DRIVING"
},
// cut
{
"distance" : {
"text" : "52 m",
"value" : 52
},
"duration" : {
"text" : "1 min",
"value" : 14
},
"end_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"html_instructions" : "Continua su \u003cb\u003eVia Santa Margherita\u003c/b\u003e",
"polyline" : {
"points" : "ogotGoxaw@`@`@j@h@"
},
"start_location" : {
"lat" : 45.4669622,
"lng" : 9.189359399999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 192
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"html_instructions" : "Svolta a \u003cb\u003esinistra\u003c/b\u003e e prendi \u003cb\u003eVia Silvio Pellico\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "aeotGcvaw@Xw@DCBAxC@~A?d@A"
},
"start_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "A1/E35 e A1",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
如果我使用 "transit" 没有到达时间,它会起作用:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.
189981999999986&mode=transit&key=++API_KEY++
和:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJRYxePKzGhkcRsgPwamn2Pfo",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4969308,
"lng" : 12.5528041
},
"southwest" : {
"lat" : 41.892252,
"lng" : 9.188611
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169733
},
"departure_time" : {
"text" : "10:10",
"time_zone" : "Europe/Rome",
"value" : 1513156231
},
"distance" : {
"text" : "571 km",
"value" : 571467
},
"duration" : {
"text" : "3 ore 45 min",
"value" : 13502
},
"end_address" : "Piazza del Duomo, 1, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "0,1 km",
"value" : 102
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Cammina fino a Repubblica",
"polyline" : {
"points" : "wcw~F_vgkA@CBADABA@A@?B?D?B?B@B?B@BBB@@BBBDH@D@H@@?D?BDRBL?@DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "54 m",
"value" : 54
},
"duration" : {
"text" : "1 min",
"value" : 49
},
"end_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"html_instructions" : "Procedi in direzione \u003cb\u003esudest\u003c/b\u003e verso \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "wcw~F_vgkA@CBADABA@A@?B?D?B?B@B?B@BBB@@BBBDH@D@H@@?D?B"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "48 m",
"value" : 48
},
"duration" : {
"text" : "1 min",
"value" : 38
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Esci dalla rotonda e prendi \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "oaw~FstgkADRBL?@DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"travel_mode" : "WALKING"
}
],
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,4 km",
"value" : 437
},
"duration" : {
"text" : "1 min",
"value" : 46
},
"end_location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"html_instructions" : "Metropolitana verso Anagnina",
"polyline" : {
"points" : "u_w~FwqgkAeBIBoA@I|ByM~CmELR"
},
"start_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"name" : "Termini"
},
"arrival_time" : {
"text" : "10:12",
"time_zone" : "Europe/Rome",
"value" : 1513156353
},
"departure_stop" : {
"location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"name" : "Repubblica"
},
"departure_time" : {
"text" : "10:11",
"time_zone" : "Europe/Rome",
"value" : 1513156307
},
"headsign" : "Anagnina",
"line" : {
"agencies" : [
{
"name" : "Atac",
"phone" : "011 39 06 57003",
"url" : "http://www.atac.roma.it/"
}
],
"color" : "#e27439",
"name" : "Metro A",
"short_name" : "MEA",
"url" : "http://muovi.roma.it/percorso/js?query=MEA&cl=1",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 1
},
"travel_mode" : "TRANSIT"
},
{
"distance" : {
"text" : "2,6 km",
"value" : 2641
},
"duration" : {
"text" : "6 min",
"value" : 330
},
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"html_instructions" : "Metropolitana verso San Donato",
"polyline" : {
"points" : "//collapsed//"
},
"start_location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"name" : "Duomo"
},
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169730
},
"departure_stop" : {
"location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"name" : "Centrale FS"
},
"departure_time" : {
"text" : "13:50",
"time_zone" : "Europe/Rome",
"value" : 1513169400
},
"headsign" : "San Donato",
"line" : {
"agencies" : [
{
"name" : "COMUNE DI MILANO",
"phone" : "011 39 02 0202",
"url" : "http://www.muoversi.milano.it/"
}
],
"color" : "#ffea00",
"name" : "M3 - Linea Gialla",
"short_name" : "3",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 4
},
"travel_mode" : "TRANSIT"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "",
"warnings" : [
"Le indicazioni per tragitti a piedi sono in versione beta. Presta attenzione – questo percorso potrebbe non disporre di marciapiede o aree pedonali."
],
"waypoint_order" : []
}
],
"status" : "OK"
}
您请求中的问题是您作为 arrival_time
参数传递的值。请注意,此值必须以秒为单位:
arrival_time — Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. You can specify either departure_time or arrival_time, but not both. Note that arrival_time must be specified as an integer.
https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests
您传递的毫秒数 1513162800000
对应于 03/22/49920 @ 8:00am (UTC)
,正确的值是 1513162800
对应于 12/13/2017 @ 11:00am (UTC)
。
请求应该是:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835%2C12.496365500000024&destination=45.4642035%2C9.189981999999986&mode=transit&arrival_time=1513162800&key=YOUR_API_KEY
路线计算器中的相同请求:
希望对您有所帮助!
如果它对其他人有帮助,我还发现将 departure_time
设置得太远(在我的情况下超过一年)会导致“ZERO_RESULTS”响应。让它更接近现在解决了这个问题。
我正在开发一个应用程序,该应用程序使用 google API 获取交通解决方案以在所需时间到达某个位置。
我调用 google API 的代码与 "driving" 和 "walking" 旅行模式完美配合,但与 "transit" 和 "bicycling"响应始终标记为状态 "ZERO_RESULTS" 并且不计算任何路由。 根据 google 文档,这意味着在必须计算解决方案的国家/地区不提供公共交通和骑自行车。 我尝试了几个国家,我总是得到相同的结果,我也尝试了概述中的 Google 示例(用于过境),但它不起作用。
我通过HTTPS请求传递的参数是:出发地、目的地、出行方式,arrival_time。 我尝试的第一件事是更改 arrival_time,以防该值引用过去或太遥远的未来,但它不起作用。
万一我没有通过 "arrival_time" 响应是完美的,但我不明白,因为在 Google 文档中很清楚 arrival_time 是一个可能的参数https 请求也带有过境旅行模式。没有这个论点,请求对我的目标是无用的。
奇怪的是,如果我通过 "transit"(到达或离开时间),响应是这样的:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
如果我传递 "bicycling"(所有其他参数不变):
{
"available_travel_modes" : [ "DRIVING", "WALKING", "TRANSIT" ],
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJu46S-ZZhLxMROG5lkwZ3D7k",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ53USP0nBhkcRjQ50xhPN_zw",
"types" : [ "locality", "political" ]
}
],
"routes" : [],
"status" : "ZERO_RESULTS"
}
所以在第二种情况下 API 说 TRANSIT 可用,这根本没有意义!
我使用的位置格式是地理坐标,以避免出现歧义。
希望我能提供足够的信息让你能够帮助我。
编辑:抱歉,我认为我的 post 已经足够清楚了。 我使用 Google 方向 API: https://developers.google.com/maps/documentation/directions/
我的问题是 "transit" 和 "bicycling" 作为旅行模式,不是代码问题,但问题出现在 https 响应级别,即使使用 google 示例也是如此对于可以在概述中找到的 "transit",我获得了 "ZERO_RESULTS" 响应。 这是示例的URL:
https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&mode=transit&arrival_time=1391374800&key=YOUR_API_KEY
下面是两个 URL,它们让我得到了我在上面复制的两个回复: 有中转:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
骑自行车:
https://maps.googleapis.com/maps/api/directions/json?origin=Rome&destination=Milan&mode=transit&arrival_time=1513162800000&key=++API_KEY++
在我用于起点和终点地理坐标的代码中,如下所示:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=transit&arrival_time=1513162800000&key=++API_KEY++
唯一的区别是 google 不识别地理编码 waypoints:
{
"available_travel_modes" : [ "DRIVING", "WALKING" ],
"geocoded_waypoints" : [ {}, {} ],
"routes" : [],
"status" : "ZERO_RESULTS"
}
如果我使用 "driving" 作为旅行模式,这有效:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.189981999999986&mode=driving&arrival_time=1513162800000&key=++API_KEY++
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJC5u9LazGhkcRXAZQFNDTpKc",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4731019,
"lng" : 12.6177051
},
"southwest" : {
"lat" : 41.9028523,
"lng" : 9.1839517
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "573 km",
"value" : 572600
},
"duration" : {
"text" : "5 ore 51 min",
"value" : 21069
},
"end_address" : "Via Silvio Pellico, 2, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"steps" : [
{
"distance" : {
"text" : "93 m",
"value" : 93
},
"duration" : {
"text" : "1 min",
"value" : 19
},
"end_location" : {
"lat" : 41.9035781,
"lng" : 12.4959908
},
"html_instructions" : "Procedi in direzione \u003cb\u003enord\u003c/b\u003e da \u003cb\u003ePiazza della Repubblica\u003c/b\u003e verso \u003cb\u003eVia Giuseppe Romita\u003c/b\u003e",
"polyline" : {
"points" : "ycw~F}ugkAU?I@E@E@a@RG@EDED_@d@OP"
},
"start_location" : {
"lat" : 41.9028523,
"lng" : 12.4964704
},
"travel_mode" : "DRIVING"
},
// cut
{
"distance" : {
"text" : "52 m",
"value" : 52
},
"duration" : {
"text" : "1 min",
"value" : 14
},
"end_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"html_instructions" : "Continua su \u003cb\u003eVia Santa Margherita\u003c/b\u003e",
"polyline" : {
"points" : "ogotGoxaw@`@`@j@h@"
},
"start_location" : {
"lat" : 45.4669622,
"lng" : 9.189359399999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 192
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 45.46495119999999,
"lng" : 9.1892874
},
"html_instructions" : "Svolta a \u003cb\u003esinistra\u003c/b\u003e e prendi \u003cb\u003eVia Silvio Pellico\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "aeotGcvaw@Xw@DCBAxC@~A?d@A"
},
"start_location" : {
"lat" : 45.4665738,
"lng" : 9.1889772
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "A1/E35 e A1",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
如果我使用 "transit" 没有到达时间,它会起作用:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835,12.496365500000024&destination=45.4642035,9.
189981999999986&mode=transit&key=++API_KEY++
和:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "EjJQaWF6emEgZGVsbGEgUmVwdWJibGljYSwgMTAsIDAwMTg1IFJvbWEgUk0sIEl0YWxpYQ",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJRYxePKzGhkcRsgPwamn2Pfo",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 45.4969308,
"lng" : 12.5528041
},
"southwest" : {
"lat" : 41.892252,
"lng" : 9.188611
}
},
"copyrights" : "Dati mappa ©2017 Google",
"legs" : [
{
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169733
},
"departure_time" : {
"text" : "10:10",
"time_zone" : "Europe/Rome",
"value" : 1513156231
},
"distance" : {
"text" : "571 km",
"value" : 571467
},
"duration" : {
"text" : "3 ore 45 min",
"value" : 13502
},
"end_address" : "Piazza del Duomo, 1, 20121 Milano MI, Italia",
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"start_address" : "Piazza della Repubblica, 10, 00185 Roma RM, Italia",
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "0,1 km",
"value" : 102
},
"duration" : {
"text" : "1 min",
"value" : 87
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Cammina fino a Repubblica",
"polyline" : {
"points" : "wcw~F_vgkA@CBADABA@A@?B?D?B?B@B?B@BBB@@BBBDH@D@H@@?D?BDRBL?@DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"steps" : [
{
"distance" : {
"text" : "54 m",
"value" : 54
},
"duration" : {
"text" : "1 min",
"value" : 49
},
"end_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"html_instructions" : "Procedi in direzione \u003cb\u003esudest\u003c/b\u003e verso \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "wcw~F_vgkA@CBADABA@A@?B?D?B?B@B?B@BBB@@BBBDH@D@H@@?D?B"
},
"start_location" : {
"lat" : 41.9028429,
"lng" : 12.4964793
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "48 m",
"value" : 48
},
"duration" : {
"text" : "1 min",
"value" : 38
},
"end_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"html_instructions" : "Esci dalla rotonda e prendi \u003cb\u003ePiazza della Repubblica\u003c/b\u003e",
"polyline" : {
"points" : "oaw~FstgkADRBL?@DXBLBJDHBFVM"
},
"start_location" : {
"lat" : 41.9024775,
"lng" : 12.4962611
},
"travel_mode" : "WALKING"
}
],
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,4 km",
"value" : 437
},
"duration" : {
"text" : "1 min",
"value" : 46
},
"end_location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"html_instructions" : "Metropolitana verso Anagnina",
"polyline" : {
"points" : "u_w~FwqgkAeBIBoA@I|ByM~CmELR"
},
"start_location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 41.9011732,
"lng" : 12.4996019
},
"name" : "Termini"
},
"arrival_time" : {
"text" : "10:12",
"time_zone" : "Europe/Rome",
"value" : 1513156353
},
"departure_stop" : {
"location" : {
"lat" : 41.902193,
"lng" : 12.4958041
},
"name" : "Repubblica"
},
"departure_time" : {
"text" : "10:11",
"time_zone" : "Europe/Rome",
"value" : 1513156307
},
"headsign" : "Anagnina",
"line" : {
"agencies" : [
{
"name" : "Atac",
"phone" : "011 39 06 57003",
"url" : "http://www.atac.roma.it/"
}
],
"color" : "#e27439",
"name" : "Metro A",
"short_name" : "MEA",
"url" : "http://muovi.roma.it/percorso/js?query=MEA&cl=1",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 1
},
"travel_mode" : "TRANSIT"
},
{
"distance" : {
"text" : "2,6 km",
"value" : 2641
},
"duration" : {
"text" : "6 min",
"value" : 330
},
"end_location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"html_instructions" : "Metropolitana verso San Donato",
"polyline" : {
"points" : "//collapsed//"
},
"start_location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"transit_details" : {
"arrival_stop" : {
"location" : {
"lat" : 45.4639037,
"lng" : 9.188611
},
"name" : "Duomo"
},
"arrival_time" : {
"text" : "13:55",
"time_zone" : "Europe/Rome",
"value" : 1513169730
},
"departure_stop" : {
"location" : {
"lat" : 45.4844397,
"lng" : 9.202612799999999
},
"name" : "Centrale FS"
},
"departure_time" : {
"text" : "13:50",
"time_zone" : "Europe/Rome",
"value" : 1513169400
},
"headsign" : "San Donato",
"line" : {
"agencies" : [
{
"name" : "COMUNE DI MILANO",
"phone" : "011 39 02 0202",
"url" : "http://www.muoversi.milano.it/"
}
],
"color" : "#ffea00",
"name" : "M3 - Linea Gialla",
"short_name" : "3",
"vehicle" : {
"icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png",
"local_icon" : "//maps.gstatic.com/mapfiles/transit/iw2/6/it-metro.png",
"name" : "Metropolitana",
"type" : "SUBWAY"
}
},
"num_stops" : 4
},
"travel_mode" : "TRANSIT"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "//collapsed//"
},
"summary" : "",
"warnings" : [
"Le indicazioni per tragitti a piedi sono in versione beta. Presta attenzione – questo percorso potrebbe non disporre di marciapiede o aree pedonali."
],
"waypoint_order" : []
}
],
"status" : "OK"
}
您请求中的问题是您作为 arrival_time
参数传递的值。请注意,此值必须以秒为单位:
arrival_time — Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. You can specify either departure_time or arrival_time, but not both. Note that arrival_time must be specified as an integer.
https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests
您传递的毫秒数 1513162800000
对应于 03/22/49920 @ 8:00am (UTC)
,正确的值是 1513162800
对应于 12/13/2017 @ 11:00am (UTC)
。
请求应该是:
https://maps.googleapis.com/maps/api/directions/json?origin=41.9027835%2C12.496365500000024&destination=45.4642035%2C9.189981999999986&mode=transit&arrival_time=1513162800&key=YOUR_API_KEY
路线计算器中的相同请求:
希望对您有所帮助!
如果它对其他人有帮助,我还发现将 departure_time
设置得太远(在我的情况下超过一年)会导致“ZERO_RESULTS”响应。让它更接近现在解决了这个问题。