4

我爲Android使用Places.GeoDataApi,根據執行請求的設備的位置,我得到不同的搜索結果。我需要結果始終位於邊界內。我沒有看到可以在getAutocompletePredictions請求中設置的位置。有什麼我失蹤?如何在界限內獲取Places.GeoDataApi.getAutocompletePredictions?

我得到使用GoogleApiClient和地點API通過地址/位自動完成建議:

Places.GeoDataApi.getAutocompletePredictions() 

該方法需要GoogleApiClient對象,String自動完成,並且對象的LatLngBounds限制搜索範圍。這是我的用法是什麼樣子:

LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862)); 


GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(LocationServices.API) 
      .addApi(Places.GEO_DATA_API) 
      .build(); 


PendingResult<AutocompletePredictionBuffer> results = 
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, "Starbucks", bounds, null); 

使用的版本:com.google.android.gms:播放服務定位:8.3.0

文檔: https://developers.google.com/places/android/autocomplete

+0

案例打開: https://code.google.com/p/gmaps-api-issues/issues/detail?id=10981&thanks=10981&ts=1480591333 –

回答

2

我一樣的問題。

不幸的是,無法使用Google Places API Android獲取特定範圍內的地點。

但是,您仍然可以使用Google Places API的鄰近搜索網絡服務

文檔瀏覽: https://developers.google.com/places/web-service/search?hl=fr

然後,您應該能夠設置參數的範圍,並獲得地方從JSON響應的範圍,在這個答案解釋: https://stackoverflow.com/a/32404701/5446285

+0

謝謝傑克,我確實考慮過這種方法,但Google會提前警告您他們的文檔頁面: 「The Pl aces API Web服務和客戶端庫用於服務器應用程序「 而我的問題影響了Android客戶端。 由於我問了這個問題,我有一個同事在地圖上提交報告,他們回來說他們目前正在支持這個功能,儘管目前還沒有發佈日期。 –

+0

適用於Android的Places API功能請求:https://issuetracker.google.com/issues/38188994 – xomena