2017-12-12 11 views
0

원하는 시점에 위치에 도달 할 수있는 전송 솔루션을 얻기 위해 Google API를 사용하는 앱을 개발하고 있습니다.Google 길 찾기 API 전송은 항상 'ZERO_RESULTS'을 반환합니다.

google API를 호출하는 코드는 '주행'및 '보행'여행 모드와 완벽하게 작동하지만 응답은 '전달'및 '자전거 타기'로 상태가 항상 'ZERO_RESULTS'로 표시되며 경로는 계산되지 않습니다. Google 문서에 따르면 이는 솔루션을 계산해야하는 국가에서 대중 교통 및 자전거를 이용할 수 없음을 의미합니다. 여러 국가에서 시도한 결과 항상 동일한 결과를 얻었으며 개요의 Google 예 (전송 용)도 시도했지만 작동하지 않습니다.

HTTPS 요청과 함께 전달되는 매개 변수는 origin, destination, travel mode, arrival_time입니다. 내가 먼저 시도한 것은 arrival_time을 변경하는 것입니다. 값이 과거 또는 너무 먼 미래를 참조 할 경우를 대비하여 작동하지만 작동하지 않습니다.

"arrival_time"을 전달하지 않은 경우 응답이 완벽하지만 Google 문서에 arrival_time이 대중 교통 모드와 함께 https 요청의 가능한 인수임을 분명히하기 때문에 이해할 수 없습니다. 이 주장이 없다면 그 요구는 내 목표에 쓸모가 없다.

호기심 것은 내가 (도착 또는 출발 시간) "통과"를 전달하면 응답이 때문이다 :

{ 
    "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" 
} 

을 내가 (다른 모든 매개 변수 변경과 함께) "자전거"를 전달하는 경우 :

{ 
    "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를 사용할 수 있으며 이는 전혀 이해가되지 않는다고 말했습니다.

내가 사용하는 위치의 형식은 모호한 경우를 피하기 위해 지리적 좌표입니다.

당신이 나를 도울 수 있도록 충분한 정보를 제공하기를 바랍니다.

편집 : 죄송합니다. 제 게시물이 충분히 명확하다고 생각했습니다. 나는 구글 길 찾기 API를 사용 https://developers.google.com/maps/documentation/directions/

내 문제가 여행 모드로 "전송"과 "자전거"로하고 코드 문제가되지 않습니다,하지만 문제는 심지어 구글의 예를 들어이 https 응답의 수준에 나타납니다 개요에서 찾을 수있는 "대중 교통"은 "ZERO_RESULTS"응답을 얻습니다.여기

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은 다음과 같습니다 : 이 예제의 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=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}[email protected]@[email protected]@[email protected][email protected]@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" : "[email protected]`@`@[email protected]@" 
        }, 
        "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" : "[email protected]@[email protected][email protected]" 
        }, 
        "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" 
} 

을 내가 "통과"를 사용하는 경우 :이 일 여행 모드로 "운전"사용하는 경우

{ 
    "available_travel_modes" : [ "DRIVING", "WALKING" ], 
    "geocoded_waypoints" : [ {}, {} ], 
    "routes" : [], 
    "status" : "ZERO_RESULTS" 
} 

: 16,

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++ 

유일한 차이점은 구글 지오 코딩 중간 점을 인식하지 않는다는 것입니다 도착 시간없이 작동 :

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" : "[email protected]@[email protected][email protected][email protected]@@[email protected]@[email protected]@[email protected]" 
        }, 
        "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" : "[email protected]@[email protected][email protected][email protected]@@[email protected]@[email protected]@?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" : "[email protected]" 
          }, 
          "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" : "[email protected]|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 매개 변수로 전달할 값입니다 당신에게

+0

문제가있는 [mcve]를 제공해주십시오. 위의 응답에서 Google지도 Javascript API 길 찾기 서비스 요청에서 장소 ID를 사용하면 작동하는 것 같습니다 (도착 시간과 출발 시간이 표시된 TRANSIT 응답). – geocodezip

+0

나는 나의 포스트를 편집했다, 이것이 더 명확 할 것이기를 바란다! –

답변

0

감사드립니다. 이 값이 초에 있어야 있습니다 :

ARRIVAL_TIME는 - 대중 교통 길 찾기에 도착 원하는 시간을 지정, 초 자정 이후 1970 년 1 월 1 일 UTC에서 . departure_time 또는 arrival_time 중 하나를 지정할 수 있지만 둘 다를 지정할 수는 없습니다. arrival_time은 정수로 지정해야합니다. 당신은 03/22/49920 @ 8:00am (UTC)에 해당 밀리 초 1513162800000을 전달하는

https://developers.google.com/maps/documentation/directions/intro#DirectionsRequests

, 올바른 값은 12/13/2017 @ 11:00am (UTC)에 해당 1513162800입니다.

요청해야한다 :

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

길 계산기의 동일한 요청 :

https://directionsdebug.firebaseapp.com/?origin=41.9027835%2C12.496365500000024&destination=45.4642035%2C9.189981999999986&mode=transit&arrival_time=1513162800

난이 도움이되기를 바랍니다!

+0

감사합니다. 시간 형식이 올바르지 않다는 것이 궁금 해서요. 그러나 운전과 걷기가 작동한다는 사실이 저를 잘못 알고 있습니다. –