2017-06-21 14 views
0

我通過「place id」發現PlacesService.getDetails存在AutoCompleteService.getPlacePredictions返回這些id的結果問題。Google AutoCompleteService返回PlaceService不知道的地方

這裏是我的代碼(也爲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不知道自動完成服務的結果中返回的placeId。

有人知道這裏發生了什麼嗎?

+0

我得到兩個([小提琴]狀態OK(https://jsfiddle.net/geocodezip/cu2qtc0x/4 /)) – geocodezip

+0

感謝您看看@geocodezip。這是我從你的小提琴得到: ChIJdd3kdPR544kRllG3JcXaViQ ChIJq7N18T1awokRXtu1sjDO7Jw 狀態= OK,地址= 401公園博士,波士頓,MA 02215,USA 遺漏的類型錯誤:無法讀取屬性 '的formatted_address' 空 –

+0

我得到: ChIJdd3kdPR544kRllG3JcXaViQ EjsxMjAgV2FsbCBTdHJlZXQsIFN0YXRlbiBJc2xhbmQsIE5ldyBZb3JrLCBOWSwgVW5pdGVkIFN0YXRlcw status = OK,address = 120 Wall St,Staten Island,NY 10301,USA status = OK,address = 401 Park Dr,Boston,MA 02215,USA 也許您連接到不一致的服務器然而)。 – geocodezip

回答

相關問題