我遇到了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。
有谁知道这里发生了什么?