12

我正在使用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();
    }

提前致谢,

4

4 回答 4

20

我正在寻找同样的东西。我不同意标记为正确的答案。我可能是错的,但似乎“Thoroughfare”(多么古朴的英文术语!)是提供街道名称的字段。例如:

获取地址:

    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();
    }
于 2013-03-03T01:35:37.593 回答
1

您可能从中获取门牌号的功能是getSubThoroughfare().

于 2014-11-21T21:28:51.193 回答
0

这是我的代码示例,并显示地址、城市等。我希望这对你有所帮助..

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

如果您查看更多信息或示例,请查看此链接

于 2016-01-26T16:34:47.413 回答
-1

看一下 Address 类。

Android 开发者:地址

于 2012-09-14T05:53:39.157 回答