Get City Name and Postal Code from Google Place API on Android

How to get city and state name in Autocomplete Places _ Places API

Use like this:-

and onActivityResult

 if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = Autocomplete.getPlaceFromIntent(data);
LatLng latLng = place.getLatLng();
double MyLat = latLng.latitude;
double MyLong = latLng.longitude;
Geocoder geocoder = new Geocoder(EditProfileActivity.this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(MyLat, MyLong, 1);
String stateName = addresses.get(0).getAdminArea();
String cityName = addresses.get(0).getLocality();
edit_profile_city_editText.setText(place.getName() + "," + stateName);
} catch (IOException e) {
e.printStackTrace();

}

Hope this will help you.Thanks..

Android Google Places API- Is there any way to get the city from Place objects?

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);

Google places api only include results that have postal_code

It's not currently possible to filter places from Place Autocomplete predictions on postal codes only.

However, there is an open feature request in Google's Issue Tracker which I suggest starring to increase visibility and subscribe to future notifications:

https://issuetracker.google.com/issues/35822067

Hope this helps!



Related Topics



Leave a reply



Submit