有没有办法从location或lat或long获取当前用户位置的邮政编码?如果是这样的话,是怎么做的?
发布于 2011-05-02 18:07:41
是的,你can...All你需要做的就是提取
http://maps.google.com/maps/geo?ll=latitude,经度
http://maps.google.com/maps/geo?ll=10.345561,123.896932或者尝试这个解决方案。我可以给你一个想法。
你可以拥有一座城市,对吧?WIth这个json数据,如果您有一个采用这种格式的zipcode的数据库(在maxmind.com)。
CountryCode |城市| ZipCode
PH |Cebu |6000
现在查询与googles返回的国家代码相关的数据库。
更新
地理编码接口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
发布于 2011-11-25 14:28:50
使用安卓Geocoder API!
getFromLocation(double,double,int)就是您所需要的。
发布于 2014-06-17 14:46:09
基于地理编码器的实现:
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;
}您还可以从地址中获取其他信息,例如城市名称。
https://stackoverflow.com/questions/5855843
复制相似问题