2016-04-19 98 views
1

因此,我試圖根據Google地方文本搜索來獲取詳細信息。我的文本搜索工作正常,但爲了獲取詳細信息,我不斷收到「無效的請求」。Google Places API獲取詳細信息 - 無效請求

我已經按照從文檔,以及其他人,但沒有用實例的例子,我已經失敗....

這是我的文本搜索,這是工作。

var lat = '43.09182244507046' 
var lng = '-89.48985488807972' 
var places; 
    function initialize() { 


     var location = new google.maps.LatLng(lat,lng); 

     var map = new google.maps.Map(document.getElementById('map'),{ 
      center: location, 
      zoom: 15 
     }); 

     var request = { 
      location: location, 
      radius: '50000', 
      query: 'food' 
     }; 

     var callback = function (results, status) { 
       places = results; 
       console.log(status); 
       console.log(places); 
     } 

     var service = new google.maps.places.PlacesService(map); 
     service.textSearch(request, callback); 

    } 

這是我的地方詳細信息搜索這是越來越無效請求狀態

var place_details; 
     function getDetails() { 

      var location = new google.maps.LatLng(lat,lng); 

      var map = new google.maps.Map(document.getElementById('map'),{ 
       center: location, 
       zoom: 15 
      }); 

      var callback = function (results, status) { 
       place_details = results; 
      }; 

      var service = new google.maps.places.PlacesService(map); 
      service.getDetails({ 
       placeId: "8deae188679ff8b9344085de5360a769879240f9"}, function(place, status){ 
        place_details = place; 
        console.log(place_details); 
        console.log(status); 
       } 
      ); 
     } 

我有,如果(狀態=== google.maps.places.PlaceService.OK)在那裏。所以這不是問題,如果有人抓住了這一點。

任何幫助,將不勝感激...我想這個工作!

回答

3

8deae188679ff8b9344085de5360a769879240f9不是地點ID。我懷疑你使用的是PlaceResult.id,它不適用於詳細請求,並且是deprecated

改爲使用PlaceResult.placeId。有關詳細信息和示例,請參見the documentation

+0

那真是個愚蠢的錯誤。它使我搜索論壇幾個小時。非常感謝。 – Talha

+0

很高興我能幫忙,@Talha。 – spiv

+1

我嘗試使用'PlaceResult.placeId',但這也沒有工作(我得到了'undefined'),使用Places API V3它似乎被命名爲'PlaceResult.place_id'。 – SidOfc

相關問題