我正在尝试获取origin -> waypoint -> destination
的路线
除了一个特定的要求外,一切都很顺利:
起源(A点): PH Benidor,Calle GasparO.Hernández,Panamá
Waypoint(B点): BAC Credomatic | Sucursal Plaza New York,Calle 50,Panamá
目的地(A点): PH Benidor,Calle GasparO.Hernández,Panamá
因此,如果我从A -> B
提出请求 - 一切正常,那么B -> A
也可以。 A -> A
也适用。只要我为特定(B)地址执行航点,Google API就会返回 ZERO_RESULT 。
检查网址:https://maps.googleapis.com/maps/api/directions/json?key=<API_KEY>&mode=driving&origin=PH+Benidor%2C+Calle+Gaspar+O.+Hern%C3%A1ndez%2C+Panam%C3%A1&destination=PH+Benidor%2C+Calle+Gaspar+O.+Hern%C3%A1ndez%2C+Panam%C3%A1&alternatives=true&units=metric&waypoints=BAC+Credomatic+|+Sucursal+Plaza+New+York%2C+Calle+50%2C+Panam%C3%A1
更新
地址取自Google自动填充API字段,因此我假设它们格式正确。来自A -> B
的路线适用于相同的地址
https://maps.googleapis.com/maps/api/directions/json?key=API_KEY&alternatives=true&units=metric&mode=driving&origin=PH+Benidor%2C+Calle+Gaspar+O.+Hern%C3%A1ndez%2C+Panam%C3%A1&destination=BAC+Credomatic+|+Sucursal+Plaza+New+York%2C+Calle+50%2C+Panam%C3%A1
响应的
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJxX3EIvqorI8RRhwI3jYajZc",
"types" : [ "premise" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJMR2dd-OorI8ROKhRZctCf0k",
"types" : [
"bus_station",
"establishment",
"point_of_interest",
"transit_station"
]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 8.9896817,
"lng" : -79.52026149999999
},
"southwest" : {
"lat" : 8.979656199999999,
"lng" : -79.52709229999999
}
},
"copyrights" : "Картографические данные © 2017 Google",
"legs" : [
{
"distance" : {
"text" : "2,1 км",
"value" : 2052
},
"duration" : {
"text" : "8 мин.",
"value" : 480
},
"end_address" : "Calle 50, Panamá, Панама",
"end_location" : {
"lat" : 8.982186499999999,
"lng" : -79.52026149999999
},
"start_address" : "PH Benidor, Calle Gaspar O. Hernández, Panamá, Панама",
"start_location" : {
"lat" : 8.9896817,
"lng" : -79.5251863
},
"steps" : [
{
"distance" : {
"text" : "0,1 км",
"value" : 111
},
"duration" : {
"text" : "1 мин.",
"value" : 50
},
"end_location" : {
"lat" : 8.9887005,
"lng" : -79.52522759999999
},
"html_instructions" : "Направляйтесь на \u003cb\u003eюг\u003c/b\u003e по \u003cb\u003eCalle Gaspar O. Hernández\u003c/b\u003e в сторону \u003cb\u003eVía Argentina\u003c/b\u003e",
"polyline" : {
"points" : "oxzu@lgkdNbDR^K"
},
"start_location" : {
"lat" : 8.9896817,
"lng" : -79.5251863
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 241
},
"duration" : {
"text" : "2 мин.",
"value" : 99
},
"end_location" : {
"lat" : 8.987735199999999,
"lng" : -79.52327099999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eVía Argentina\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "krzu@tgkdNDKr@wBLc@N[b@kAr@}AHQBE@A"
},
"start_location" : {
"lat" : 8.9887005,
"lng" : -79.52522759999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,7 км",
"value" : 737
},
"duration" : {
"text" : "2 мин.",
"value" : 128
},
"end_location" : {
"lat" : 8.982404600000001,
"lng" : -79.52709229999999
},
"html_instructions" : "Поверните \u003cb\u003eнаправо\u003c/b\u003e на \u003cb\u003eVía España\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "klzu@l{jdNf@Hl@Nb@Ld@Lj@Xn@`@z@t@Zd@JRHJT\\PVPPNNVNj@^\\P`FzCh@VhAp@j@p@@@pCxA"
},
"start_location" : {
"lat" : 8.987735199999999,
"lng" : -79.52327099999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,4 км",
"value" : 424
},
"duration" : {
"text" : "2 мин.",
"value" : 105
},
"end_location" : {
"lat" : 8.979656199999999,
"lng" : -79.5244422
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eCalle Aquilino de la Guardia\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "_kyu@hskdNBE@ADE`CcDp@w@d@i@j@e@xBeBd@[~@s@p@a@"
},
"start_location" : {
"lat" : 8.982404600000001,
"lng" : -79.52709229999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,5 км",
"value" : 539
},
"duration" : {
"text" : "2 мин.",
"value" : 98
},
"end_location" : {
"lat" : 8.982186499999999,
"lng" : -79.52026149999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eCalle 50\u003c/b\u003e/\u003cb\u003eCalle Nicanor de Obarrio\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eПункт назначения будет справа\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "{yxu@vbkdNkAcCmAgCOWm@kACECCg@gAm@aA}CcGe@{@"
},
"start_location" : {
"lat" : 8.979656199999999,
"lng" : -79.5244422
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "oxzu@lgkdNbDR^KDK`A{Cr@gB|@oBDGtAXhAZj@Xn@`@z@t@Zd@T^f@t@`@`@bAn@~FlDrBhAl@r@pCxABEFGrD{EpAoA~CaC~@s@p@a@yCkGeAmBuAiCcE_I"
},
"summary" : "Vía España и Calle 50/Calle Nicanor de Obarrio",
"warnings" : [],
"waypoint_order" : []
},
{
"bounds" : {
"northeast" : {
"lat" : 8.9896817,
"lng" : -79.52026149999999
},
"southwest" : {
"lat" : 8.9806346,
"lng" : -79.52528719999999
}
},
"copyrights" : "Картографические данные © 2017 Google",
"legs" : [
{
"distance" : {
"text" : "2,1 км",
"value" : 2149
},
"duration" : {
"text" : "10 мин.",
"value" : 588
},
"end_address" : "Calle 50, Panamá, Панама",
"end_location" : {
"lat" : 8.982186499999999,
"lng" : -79.52026149999999
},
"start_address" : "PH Benidor, Calle Gaspar O. Hernández, Panamá, Панама",
"start_location" : {
"lat" : 8.9896817,
"lng" : -79.5251863
},
"steps" : [
{
"distance" : {
"text" : "0,1 км",
"value" : 111
},
"duration" : {
"text" : "1 мин.",
"value" : 50
},
"end_location" : {
"lat" : 8.9887005,
"lng" : -79.52522759999999
},
"html_instructions" : "Направляйтесь на \u003cb\u003eюг\u003c/b\u003e по \u003cb\u003eCalle Gaspar O. Hernández\u003c/b\u003e в сторону \u003cb\u003eVía Argentina\u003c/b\u003e",
"polyline" : {
"points" : "oxzu@lgkdNbDR^K"
},
"start_location" : {
"lat" : 8.9896817,
"lng" : -79.5251863
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 241
},
"duration" : {
"text" : "2 мин.",
"value" : 99
},
"end_location" : {
"lat" : 8.987735199999999,
"lng" : -79.52327099999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eVía Argentina\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "krzu@tgkdNDKr@wBLc@N[b@kAr@}AHQBE@A"
},
"start_location" : {
"lat" : 8.9887005,
"lng" : -79.52522759999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 238
},
"duration" : {
"text" : "1 мин.",
"value" : 43
},
"end_location" : {
"lat" : 8.985976599999999,
"lng" : -79.52439769999999
},
"html_instructions" : "Поверните \u003cb\u003eнаправо\u003c/b\u003e на \u003cb\u003eVía España\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "klzu@l{jdNf@Hl@Nb@Ld@Lj@Xn@`@z@t@Zd@JR"
},
"start_location" : {
"lat" : 8.987735199999999,
"lng" : -79.52327099999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 231
},
"duration" : {
"text" : "1 мин.",
"value" : 59
},
"end_location" : {
"lat" : 8.9846278,
"lng" : -79.5227939
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eCalle 52 Este\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "kazu@nbkdNFGR]pF{G"
},
"start_location" : {
"lat" : 8.985976599999999,
"lng" : -79.52439769999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,1 км",
"value" : 149
},
"duration" : {
"text" : "1 мин.",
"value" : 62
},
"end_location" : {
"lat" : 8.9853383,
"lng" : -79.52164499999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eAv. Samuel Lewis\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "}xyu@lxjdNWe@MSMQyAyC"
},
"start_location" : {
"lat" : 8.9846278,
"lng" : -79.5227939
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 183
},
"duration" : {
"text" : "1 мин.",
"value" : 41
},
"end_location" : {
"lat" : 8.9839468,
"lng" : -79.52075069999999
},
"html_instructions" : "Поверните \u003cb\u003eнаправо\u003c/b\u003e на \u003cb\u003eCalle 54 Este\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "k}yu@fqjdNpGmDBC"
},
"start_location" : {
"lat" : 8.9853383,
"lng" : -79.52164499999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,3 км",
"value" : 332
},
"duration" : {
"text" : "1 мин.",
"value" : 74
},
"end_location" : {
"lat" : 8.982836499999999,
"lng" : -79.5233909
},
"html_instructions" : "Поверните \u003cb\u003eнаправо\u003c/b\u003e на перекрестке 1 на \u003cb\u003eAv. Ricardo Arango\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "utyu@tkjdNzAlC@@rCvESfD"
},
"start_location" : {
"lat" : 8.9839468,
"lng" : -79.52075069999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "88 м",
"value" : 88
},
"duration" : {
"text" : "1 мин.",
"value" : 19
},
"end_location" : {
"lat" : 8.982181299999999,
"lng" : -79.52383399999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eAvenida Ricardo Arango\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "wmyu@d|jdNbCvA"
},
"start_location" : {
"lat" : 8.982836499999999,
"lng" : -79.5233909
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 км",
"value" : 197
},
"duration" : {
"text" : "1 мин.",
"value" : 58
},
"end_location" : {
"lat" : 8.9806346,
"lng" : -79.523155
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eCalle Beatriz M. de Cabal\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "siyu@|~jdN~BoB~AS`AAJ?F?"
},
"start_location" : {
"lat" : 8.982181299999999,
"lng" : -79.52383399999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "61 м",
"value" : 61
},
"duration" : {
"text" : "1 мин.",
"value" : 26
},
"end_location" : {
"lat" : 8.9809009,
"lng" : -79.52267329999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e в сторону \u003cb\u003eCalle 50\u003c/b\u003e/\u003cb\u003eCalle Nicanor de Obarrio\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "}_yu@vzjdNMYg@gA"
},
"start_location" : {
"lat" : 8.9806346,
"lng" : -79.523155
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "19 м",
"value" : 19
},
"duration" : {
"text" : "1 мин.",
"value" : 7
},
"end_location" : {
"lat" : 8.9807585,
"lng" : -79.52257179999999
},
"html_instructions" : "Поверните \u003cb\u003eнаправо\u003c/b\u003e в сторону \u003cb\u003eCalle 50\u003c/b\u003e/\u003cb\u003eCalle Nicanor de Obarrio\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "sayu@twjdNZQ?A"
},
"start_location" : {
"lat" : 8.9809009,
"lng" : -79.52267329999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,3 км",
"value" : 299
},
"duration" : {
"text" : "1 мин.",
"value" : 50
},
"end_location" : {
"lat" : 8.982186499999999,
"lng" : -79.52026149999999
},
"html_instructions" : "Поверните \u003cb\u003eналево\u003c/b\u003e на \u003cb\u003eCalle 50\u003c/b\u003e/\u003cb\u003eCalle Nicanor de Obarrio\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eПункт назначения будет справа\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "w`yu@`wjdNCCg@gAm@aA}CcGe@{@"
},
"start_location" : {
"lat" : 8.9807585,
"lng" : -79.52257179999999
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "oxzu@lgkdNbDR^KDK`A{Cr@gB|@oBDGtAXhAZj@Xn@`@z@t@Zd@JRFGdGyHe@y@MQyAyCtGqD|AnCrCvESfDbCvA~BoB~AS`AAR?u@aBZSk@kAkEeIe@{@"
},
"summary" : "Av. Ricardo Arango",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
因此,如果地址位于waypoints
参数中,我认为地址有问题。
答案 0 :(得分:0)
我使用您的问题中的原点,目的地和航点检查了Directions API请求
https://maps.googleapis.com/maps/api/directions/json?origin=PH%20Benidor%2C%20Calle%20Gaspar%20O.%20Hern%C3%A1ndez%2C%20Panam%C3%A1&destination=PH%20Benidor%2C%20Calle%20Gaspar%20O.%20Hern%C3%A1ndez%2C%20Panam%C3%A1&mode=driving&waypoints=BAC%20Credomatic%7CSucursal%20Plaza%20New%20York%2C%20Calle%2050%2C%20Panam%C3%A1&key=MY_API_KEY
响应包含以下地理编码航路点:
"geocoded_waypoints":[
{
"geocoder_status":"OK",
"place_id":"ChIJxX3EIvqorI8RRhwI3jYajZc",
"types":[
"premise"
]
},
{
"geocoder_status":"OK",
"place_id":"ChIJZ1RH5IDoaY8RcqGCRNAAPQw",
"types":[
"establishment","finance","point_of_interest"
]
},
{
"geocoder_status":"OK",
"place_id":"ChIJf1seg-OorI8R_66YzaG7hko",
"types":[
"bank","establishment","finance","food","point_of_interest","restaurant"
]
},
{
"geocoder_status":"OK",
"place_id":"ChIJxX3EIvqorI8RRhwI3jYajZc",
"types":[
"premise"
]
}]
让我们看看地点ID为ChIJZ1RH5IDoaY8RcqGCRNAAPQw的航路点。它对应于&#39; BAC Credomatic&#39;在你的请求中。如果您使用地理编码工具检查地点ID,您会看到&#39; BAC Credomatic&#39;被解决到位于岛上的洪都拉斯的商业地点,无法驾车到达。
这是ZERO_RESULTS的原因。在指定航点的地址时,您必须更加精确。请查看以下文档,该文档说明了如何正确格式化地址字符串:
https://developers.google.com/maps/faq#geocoder_queryformat
我希望这有帮助!