Reputation: 193
I am using the autocomplete widget of Google Place API for Android and getting a place object, but I am not able to extract the city of it, just only the complete address as a text.
Apparently, the Place interface does not have a method to return the city.
The city is the address componenets is Locality and Administrative Area Level 3, according this documentation.
Does someone knows any way to get the city of the Place object ?
Upvotes: 2
Views: 687
Reputation: 3287
It is a hack but it works. You can take the lat and lng from the Place
object and find the city from the Geocoder.
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(MyLat, MyLong, 1);
String cityName = addresses.get(0).getAddressLine(0);
String stateName = addresses.get(0).getAddressLine(1);
String countryName = addresses.get(0).getAddressLine(2);
Upvotes: 1