使用Android如何从地理编码器返回的地址获取街道名(Android how to get the

2019-07-31 14:22发布

我使用的Geocoder相反的方式来从给定的纬度和经度获取地址。

你知道如何从获取Address 只有街道名

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

提前致谢,

Answer 1:

我在寻找了同样的事情。 我不同意这是标记为正确答案。 我可能是错的,但它会出现“通途”(什么是古雅的英文名词!)是提供街道名称字段。 因此,例如:

得到地址:

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


Answer 2:

而功能你可能会得到的街道号码从为getSubThoroughfare().



Answer 3:

这是我的代码,并显示addrees,城市等的例子。我希望这有助于你..

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

如果你看的更多信息或例子来看一下这个链接



Answer 4:

看看Address类。

Android开发者:地址



文章来源: Android how to get the street name from an address returned by Geocoder