Google AutoCompleteService会返回PlacesService不知道ID的地方

时间:2017-06-21 00:32:56

标签: javascript google-maps google-api google-places-api

我遇到了PlaceService.getDetails的问题"将id"从AutoCompleteService.getPlacePredictions返回这些ID的结果。

这是我的代码(也在this JSFiddle):

function initService() {
  var placesService = new google.maps.places.PlacesService(window.document.createElement('div'));
  var autocompleteService = new google.maps.places.AutocompleteService();

  var showAddress = function(input) {
    autocompleteService.getPlacePredictions({ input }, displayTopSuggestion);
  }

  var displayTopSuggestion = function(predictions) {
    var placeId = predictions[0].place_id;
    placesService.getDetails({
      placeId: placeId
    }, function(place, status) {
      console.log(placeId + ": " + status);
    });
  }

  showAddress('401 Park Drive, Boston, MA');
  showAddress('120 Wall Street, New York, NY');
}

显示" OK"对于第一个(很酷)和"未找到"对于第二个(令人困惑):

ChIJdd3kdPR544kRllG3JcXaViQ: OK
ChIJq7N18T1awokRXtu1sjDO7Jw: NOT_FOUND

也就是说,PlacesService并不知道AutocompleteService在结果中返回的placeId。

有谁知道这里发生了什么?

1 个答案:

答案 0 :(得分:0)

这似乎可能是地图API中一个短暂问题的表现:https://issuetracker.google.com/issues/63069427

相关问题