Android how to get street name from address returned by Geocoder

I use Geocoderin the reverse order to get the address from the given lat and lon.

Do you know how to get from Address just the name of the street ?

    Geocoder geocoder = new Geocoder(AutoFinderMapActivity.this);
    try {
        List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
        if (addressList != null && addressList.size() > 0) {
            // Help here to get only the street name
            String adress = addressList.get(0).get...;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

Thanks in advance,

+5
source share
5 answers

I was looking for the same thing. I do not agree with the answer, which was marked as correct. I could be wrong, but it would seem that "Thoroughfare" (what a fancy old English term!) Is the field that provides the street name. eg,

get addresses:

    List<Address> addresses = null;
    addresses = geocoder.getFromLocation(latitude, longitude,1);
    if(addresses != null && addresses.size() > 0 ){
       Address address = addresses.get(0);
       // Thoroughfare seems to be the street name without numbers
            String street = address.getThoroughfare();
    }
+11
source

After some tests, I noticed that it address.getAddressLine(0)gives the street name and street number.

, . .

.

0

And the function that you can get from the street number is getSubThoroughfare().

0
source

This is an example of my code and show addrees, city, etc. I hope this helps you.

try {
        List<Address> addresses;
        Geocoder geocoder= new Geocoder(MyactivityName.this);
        addresses = geocoder.getFromLocation(Marker.getPosition().latitude,Marker.getPosition().longitude,1);
        if(addresses != null && addresses.size() > 0 ){
            Address address = addresses.get(0);
            String province = addresses.get(0).getAdminArea();
            Marker.setSnippet(address.getThoroughfare()+", "+province);
        }
} catch (IOException e) {
    e.printStackTrace();
}
Marker.showInfoWindow();

//get current Street name
        String address = addresses.get(0).getAddressLine(0);

        //get current province/City
        String province = addresses.get(0).getAdminArea();

        //get country
        String country = addresses.get(0).getCountryName();

        //get postal code
        String postalCode = addresses.get(0).getPostalCode();

        //get place Name
        String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL

        System.out.println("Street: " + address + "\n" + "City/Province: " + province + "\nCountry: " + country
                + "\nPostal CODE: " + postalCode + "\n" + "Place Name: " + knownName);

if you look at more information or look at this Link

0
source

Take a look at the Address class.

Android Developer: Address

-1
source

All Articles