Android how to get the street name from an address returned by Geocoder
Asked Answered
F

4

12

I'm using Geocoder in reverse way to get an address from a given lat & lon.

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

    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,

Forsook answered 14/9, 2012 at 5:47 Comment(2)
Refer this SO Link #4257329Untouchability
I have seen that question before and it does not have a clear answer about that.Forsook
R
23

I was searching up the very same thing. I disagree with the answer that was marked as correct. I could be wrong but it would appear that "Thoroughfare" (what a quaint old English term!) is the field that provides the street name. so for example:

get the 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();
    }
Ripsaw answered 3/3, 2013 at 1:35 Comment(0)
K
2

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

Karachi answered 21/11, 2014 at 21:28 Comment(0)
L
1

This is an example of my code, and show addrees, city, etc.. I hope this help 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 more information or an example look this Link

Lai answered 26/1, 2016 at 16:34 Comment(0)
F
-2

Take a look at the Address class.

Android Developer: Address

Ferro answered 14/9, 2012 at 5:53 Comment(1)
As I said above, I want to get de address name from Address.Forsook

© 2022 - 2024 — McMap. All rights reserved.