Android Geocoder类,缺少Town和Postcode

时间:2014-05-29 10:18:16

标签: android android-maps

我在Android设备上遇到地理编码问题。

Geocoder c = new Geocoder(this, Locale.getDefault());
List<Address> l = c.getFromLocation(lat, lon, 1);
for (Address a: l) {
    Log.i("GeocoderResult", "Locality " + a.getLocality() + " poscode " + a.getPostcode());
}

Android Geocoder返回android.location.Address对象。返回的文本可以包含城市和邮政编码,但相应的对象字段可能仍为空。

使用城镇和邮政编码对文本进行地理编码,但不在对象字段中进行地理编码:

50.74967518;-1.99207054:
Address text: "17 Gough Crescent, Poole, BH17, GB"
locality = null
postcode = null
Address[addressLines=[0:"17 Gough Crescent",1:"Poole",2:"BH17",3:"UK"],feature=17,admin=Poole,sub-admin=Poole,locality=null,thoroughfare=Gough Crescent,postalCode=null,countryCode=GB,countryName=United Kingdom,hasLatitude=true,latitude=50.7498262,hasLongitude=true,longitude=-1.992054,phone=null,url=null,extras=null]

使用城镇进行地理编码,并在文本和对象字段中进行邮政编码:

50.74966423;-1.99205967
Address text: 2-6 Gough Crescent, Poole BH17, GB
locality = Poole
postalCode=BH17
Address[addressLines=[0:"2-6 Gough Crescent",1:"Poole BH17",2:"UK"],feature=2-6,admin=null,sub-admin=null,locality=Poole,thoroughfare=Gough Crescent,postalCode=BH17,countryCode=GB,countryName=United Kingdom,hasLatitude=true,latitude=50.7496887,hasLongitude=true,longitude=-1.9917892,phone=null,url=null,extras=null]

我们是否遗漏了某些东西,可以使用Android Geocoder按原样检索丢失的城镇和邮政编码数据?或者是唯一的方法来猜测如果'locality'为空并尝试解析邮政编码的地址文本,哪些字段可能包含城镇数据?

0 个答案:

没有答案