ZipCode从位置

Uda*_*ran 5 android location zipcode

有没有办法从位置或纬度或长度获取当前用户位置的邮政编码.如果是这样的话?

lor*_*ong 7

使用Android Geocoder API!

getFromLocation(double,double,int)就是您所需要的.


ked*_*ter 5

是的,你可以......所有你需要做的就是提取

http://maps.google.com/maps/geo?ll= 纬度,经度

http://maps.google.com/maps/geo?ll=10.345561,123.896932
Run Code Online (Sandbox Code Playgroud)

或尝试尝试这个解决方案.我可以给你一个想法.

你可以拥有一个城市吗?有了这个json数据,如果你有一个这种格式的zipcode数据库(在maxmind.com上)

CountryCode | 城市| 邮政编码


PH |宿务| 6000

现在查询与googles返回的国家/地区代码相关的数据库.

UPDATE

Geocoding API v2已于2013年9月9日被拒绝.

这是API服务的新URL

http://maps.googleapis.com/maps/api/geocode/json?latlng=your_latitude,your_longitude

http://maps.googleapis.com/maps/api/geocode/json?latlng=10.32,123.90&sensor=true


Ale*_*nko 5

基于地理编码器的实现:

private String getZipCodeFromLocation(Location location) {
    Address addr = getAddressFromLocation(location);
    return addr.getPostalCode() == null ? "" : addr.getPostalCode();
}

private Address getAddressFromLocation(Location location) {
    Geocoder geocoder = new Geocoder(this);
    Address address = new Address(Locale.getDefault());
    try {
        List<Address> addr = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addr.size() > 0) {
            address = addr.get(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return address;
}
Run Code Online (Sandbox Code Playgroud)

您还可以从地址获取其他信息,例如城市名称。