2017-01-30 166 views
1

I don't want have different countries search suggestions in my app(Image)顯示在谷歌地圖搜索附近的地方安卓

I want to have correct or nearest suggestions in google map app(Image)

我有這個代碼

autocompleteFragment = (PlaceAutocompleteFragment) 
       getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); 
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder() 
       .setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS) 
       .build(); 

autocompleteFragment.setFilter(typeFilter); 

我想告訴附近的地方,當我在搜索欄我打字測試。我的問題是,當一個字符在搜索欄中輸入時,該字符與其他國家/地區相關的建議,我希望它是最接近的一個。換句話說,搜索是非常類似像Android谷歌地圖應用程序。

+0

只有到附近的地方纔需要網絡服務API。這個API提供了最近的地方。它不是免費的,但是開發者可以使用這個API達到一些限制。 ** API是:** https://maps.googleapis.com/maps/api/place/nearbysearch/ ** Documentaion:** https://developers.google.com/places/web-服務/搜索 – Lokesh

回答

0

AutoCompleteSearch組件不顯示附近的地方。我已經通過使用Google Map網絡服務API實現了。

Web的API: maps.googleapis.com/maps/api/place/nearbysearch (GET)
參數:密鑰(您的API密鑰),
位置(經緯度+ 「」 +郎),
半徑(5000),
傳感器(真)
注意:我啓用谷歌的地方API Web服務。

0
AutocompleteFilter filter = new AutocompleteFilter.Builder() 
      .setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES) 
      .build(); 
+0

這是行不通的。我做了。感謝您的快速響應。 – Lokesh

+0

對於預測結果 有一個簡單的解決方案。 Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient,constraint.toString(), mBounds,mPlaceFilter); 它絕對有效。 –

+0

你能分享代碼嗎?我在哪裏放你的例子? – Lokesh