Android:地址(来自地理编码)有固定格式吗?

发布于 2024-11-16 16:38:15 字数 606 浏览 6 评论 0原文

我需要确定地理位置的地址,所以我使用了 GeoCoder 和 Address,我尝试打印一个 Address 对象并得到以下结果:(

出于隐私原因,我使用了一些虚假数据,但我在设备上收到的数据是real)

Address[addressLines=[0:"123 ABC St",1:"墨尔本 VIC 1234",2:"澳大利亚"],feature=123,admin=维多利亚,sub-admin=null,locality=墨尔本,thoroughfare=ABC St,postalCode=1234,countryCode=AU,countryName=Australia,hasLatitude=true,latitude=-123.321,hasLongitude=true,longitude=123.321,phone=null,url=null,extras=null]

现在我想知道,可以吗我假设:

  1. 地址行索引 0 始终是街道地址?
  2. 索引 1 和 to 是郊区、州、邮政编码对,索引 2 是国家/地区?
  3. “特征”实际上是街道号码(即123)?
  4. “admin”是状态吗?

如果格式不固定,如何获取地址信息? 谢谢!

I need to determine the address for a geo location, so I used GeoCoder and Address, I tried to print an Address object and got the following:

(for privacy reason, I used some fake data, but the data I received on my device is real)

Address[addressLines=[0:"123 ABC St",1:"Melbourne VIC 1234",2:"Australia"],feature=123,admin=Victoria,sub-admin=null,locality=Melbourne,thoroughfare=ABC St,postalCode=1234,countryCode=AU,countryName=Australia,hasLatitude=true,latitude=-123.321,hasLongitude=true,longitude=123.321,phone=null,url=null,extras=null]

Now I'm wondering, can I assume that:

  1. address line index 0 is always the street address?
  2. and index 1 and to is the suburb, state, postcode pair, and index 2 is the country?
  3. "feature" is actually the street number(ie 123)?
  4. "admin" is state?

If the format is NOT fixed, how do I get address information?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笛声青案梦长安 2024-11-23 16:38:15

我认为格式不是固定的,您不应该依赖数组索引。来自文档:

反转的细节量
地理编码位置描述可能
有所不同,例如其中可能包含
最近的完整街道地址
建筑物,而另一个可能包含
只有城市名称和邮政编码。这
Geocoder 类需要后端
不包含在其中的服务
核心Android框架。

我相信地理编码服务是由在后台运行的谷歌地图服务实现的。您应该使用 Address 类来获取您需要的地址的元素。

I don't think that the format is fixed and you should not rely on the array indexes. From the docs:

The amount of detail in a reverse
geocoded location description may
vary, for example one might contain
the full street address of the closest
building, while another might contain
only a city name and postal code. The
Geocoder class requires a backend
service that is not included in the
core android framework.

The geocoding service is implemented by the Google Maps service which runs in the backgroind I believe. You should use Address class to fetch the elements of the address that you require.

烟酒忠诚 2024-11-23 16:38:15

这是一个可能有帮助的片段。

->使用 GeoCoder

    String currentAddress = "";

    try {
        Geocoder geoCoder = new Geocoder(context);
        List<Address> adds = geoCoder.getFromLocation(
                        latitude
                        , longitude
                        , 1);

        if (adds!=null && adds.size()>0) {
             Address add = adds.get(0);
             int max = add.getMaxAddressLineIndex();
             if (max!=-1) {
                   for (int i=0; i<max;i++)
                   currentAddress += add.getAddressLine(i) + " ";
             }
        }
}
catch (Exception ex) {
     Log.w(TAG, "geocoding_fromAndroid->"+ex.toString());
     currentAddress = "";
}

请记住,GeoCoder 并未在所有 Android 设备中实现:|在这种情况下,您可以直接使用 Google API

-> http://code.google.com/apis/maps/documentation/geocoding/

Here is a snippet that may help.

-> using GeoCoder

    String currentAddress = "";

    try {
        Geocoder geoCoder = new Geocoder(context);
        List<Address> adds = geoCoder.getFromLocation(
                        latitude
                        , longitude
                        , 1);

        if (adds!=null && adds.size()>0) {
             Address add = adds.get(0);
             int max = add.getMaxAddressLineIndex();
             if (max!=-1) {
                   for (int i=0; i<max;i++)
                   currentAddress += add.getAddressLine(i) + " ";
             }
        }
}
catch (Exception ex) {
     Log.w(TAG, "geocoding_fromAndroid->"+ex.toString());
     currentAddress = "";
}

Please keep in mind, GeoCoder is NOT implemented in all Android devices :| in this case, you can use Google API directly

-> http://code.google.com/apis/maps/documentation/geocoding/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文