到目前为止,我已经找了很多地方,但没有运气。
Android Geocoder返回
android.location.Address
对象
据我所知,这座城市应该归还
getLocality()
.
在美国国内,这似乎很有效,而在国外则不然。
我正在编写一个国际应用程序,并努力寻找一个解决方案来找出地理位置所在的城市。
以下是捷克共和国/布拉格的产出:
Address[addressLines=
[0:"Psohlavců 1764/2",
1:"147 00 Prague-Prague 4",
2:"Czech Republic"],
feature=2,
admin=Hlavnà mÄsto Praha,
sub-admin=Prague,
locality=null,
thoroughfare=Psohlavců,
postalCode=147 00,
countryCode=CZ,
countryName=Czech Republic,
hasLatitude=true,
latitude=50.0276543,
hasLongitude=true,
longitude=14.4183926,
phone=null,
url=null,
extras=null]
locality
为空,城市在
sub-admin
!
地址本身是可以的,所以地理编码器服务器似乎知道城市。
这里有一些随机的欧盟例子,但地方性在一定程度上起作用:
Address[addressLines=[0:"Nad lesem 440/34",1:"147 00 Prague-Prague 4",2:"Czech Republic"],feature=34,admin=Hlavnà mÄsto Praha,sub-admin=Prague,locality=null,thoroughfare=Nad lesem,postalCode=147 00,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.02424,hasLongitude=true,longitude=14.4117568,phone=null,url=null,extras=null]
Address[addressLines=[0:"Hauner StraÃe 4",1:"84431 Heldenstein",2:"Germany"],feature=4,admin=null,sub-admin=null,locality=Heldenstein,thoroughfare=Hauner StraÃe,postalCode=84431,countryCode=DE,countryName=Germany,hasLatitude=true,latitude=48.2540274,hasLongitude=true,longitude=12.3413535,phone=null,url=null,extras=null]
Address[addressLines=[0:"Igler StraÃe",1:"6020 Innsbruck",2:"Austria"],feature=Igler StraÃe,admin=Tyrol,sub-admin=Innsbruck,locality=Innsbruck,thoroughfare=Igler StraÃe,postalCode=6020,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.2465698,hasLongitude=true,longitude=11.4054237,phone=null,url=null,extras=null]
Address[addressLines=[0:"Durnberg 24",1:"5724 Stuhlfelden",2:"Austria"],feature=24,admin=Salzburg,sub-admin=Zell am See District,locality=null,thoroughfare=Durnberg,postalCode=5724,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.3233373,hasLongitude=true,longitude=12.4960482,phone=null,url=null,extras=null]
Address[addressLines=[0:"U RoháÄových kasáren 14",1:"100 00 Prague 10",2:"Czech Republic"],feature=14,admin=Hlavnà mÄsto Praha,sub-admin=Prague,locality=Prague 10,thoroughfare=U RoháÄových kasáren,postalCode=null,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.0704092,hasLongitude=true,longitude=14.4673473,phone=null,url=null,extras=null]
也许是我的错,但对我来说,这似乎取决于国家和地区,城市将在不同的领域被发现。
然而,地址本身似乎很好,足以发送一封邮政信。
是否有人编写了一个巧妙的函数,试图从Geocoder结果中获得更多意义?很遗憾,谷歌存储了信息,但没有正确提供。