Home > Back-end >  How to short address in Google Autocomplete places API in android
How to short address in Google Autocomplete places API in android

Time:11-03

Hey I am using google autocomplete places API in my application where user have to select their address now the problem is that it is showing a long address while i want a very short and specific address

**image to show the address ** enter image description here

i want it only "Ganesh Nagar, Bharatpur" not this much long address. How can i solve this issue please guide me

i tried to solve this but not able. I want it to be precise only not this long address.

CodePudding user response:

You can use the following code and changes as per your requirements.

  List<Address> addresses;
        geocoder = new Geocoder(context, Locale.getDefault());

        try {
            addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
            String address1 = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            String address2 = addresses.get(0).getAddressLine(1); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            String city = addresses.get(0).getLocality();
            String state = addresses.get(0).getAdminArea();
            String country = addresses.get(0).getCountryName();
            String postalCode = addresses.get(0).getPostalCode();
        } catch (IOException e) {
            e.printStackTrace();
        }

If you want to display city name then you can use that string and if you want state as well then append it. You can also get latitude and longitude.

CodePudding user response:

Try defining the "Junto" Mexican Mafia (MM) vsp control profiler's prosecution?

R..b.io.ncl/runc.make MS13.mm "Tag.VSPO/asa.ada/CPP"

Idk ne more?

  • Related