I want to get Search Results for a Specific Country. I have tried for setting Latitude and Longitude, but it may include other countries' results near to required Country!
I have seen other questions which suggest to pass &components=country:COUNTRY_NAME
in the request URL(I have seen it here). But I want to pass request from Google Places API.
I'm using following method:
Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter);
But I couldn't find any way to pass a country name for getting result for the specific country. (I have tried passing country name in the Request URL and it is working.) But how to achieve the same by using Places.GeoDataApi.getAutocompletePredictions()
method?
Or is there any other way to achieve this without sending country name in the Request URL?
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder().
setTypeFilter(Place.TYPE_COUNTRY).setCountry("IN").build();
Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.setFilter(typeFilter)
.build(this);
The
(regions)
type collection instructs the Places service to return any result matching the following types:
- locality
- sublocality
- postal_code
- country
- administrative_area_level_1
- administrative_area_level_2
The (regions) type collection is not supported in Google Places API for Android.
Reference from : Official Guide of Google Place Types.
If you want to implement this,
Use LatLng bounds with your country's specific area specified by latitude and longitude to restrict the results.
You can also use the Google Places Web Service.
Sample: For restricting your country via Web Service, showing results of country India.
URL: https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyCkvow9LlFNOywy8lzaekn-xROBZRsSFvU&input=a&types=(cities)&components=country:ind
Note: If you want to apply the country
filter to Google Places API, unfortunately you have to use WebService as of now there is no Filter/Method available in Android API to restrict by country(excluding LatLng Bounds).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With