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
How to Make a Textview Automatically Scroll as I Add More Lines of Text
How to Transfer from One Fragment to Another in Android
Adb Is Not Detecting My Android Device on Ubuntu
Android Studio - How to Find Valid Certification Path to Requested Target
How to Send a Firebase Notification to All Devices Via Curl
How Capture/Log API Calls (Function Calls) Made by Android App
How to Make Buttons Align At the Middle - Android Studio
How to Get the Full File Path from Uri
Asking Camera Permission for Webview At Runtime
Is Quitting an Application Frowned Upon
Where Is Android_Sdk_Root and How to Set It.
Photo Rotated from Camera (Samsung Device)
Touchableopacity Not Working Inside an Absolute Positioned View
Recyclerview Slow Scrolling Performance and Lag/Halt Sometime While Scrolling
How to Get the Current Time on a Button Click
How to Change Listview Height Dynamically in Android
Android: How to Send an Image as Email Attachment from Application
How to Post Raw Whole Json in the Body of a Retrofit Request