到目前爲止,我搜索了很多不幸的東西。Android地理編碼器反向位置 - 獲取城市的可靠方法?
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
爲null,城市內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結果更有意義嗎?很遺憾看到Google存儲了信息,但沒有正確提供。
是的。它在一些國家有所不同。先看看本地,如果是空的,檢查子管理。 – dannyroa
如果地方是空的,你確定子管理是可靠的嗎? – John
基於我的經驗,它可以在本地或子管理。沒有遇到兩個都是空的場景。 – dannyroa