【问题标题】:Getting list of countries, cities and their areas/states/towns respectively [closed]分别获取国家、城市及其地区/州/城镇的列表[关闭]
【发布时间】:2016-11-08 15:48:09
【问题描述】:

这是否可以在微调器中加载所有国家/地区的列表,然后在选择特定国家时,其所有城市都会出现在另一个微调器中,选择城市后,我们会获得该城市的地区或城镇列表android 使用 google-api 或类似国家/地区选择器的东西? 目前我正在使用它来获取国家/地区列表。但是如何获得各自的城镇呢?

    ArrayList<String> list=new ArrayList<String>();
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
    Locale obj = new Locale("", countryCode);
    list.add(obj.getDisplayCountry());
}

【问题讨论】:

  • 我用两个微调器来做这个。
  • 我认为 Google Maps API 无法获取该国所有城市的列表。这些 API 不像数据库搜索那样工作。
  • 注意:这个问题是要求对 API 提出建议,这在 Stack Overflow 上是不允许的。请参阅help center

标签: android google-maps google-api android-spinner


【解决方案1】:

您可以使用可用的 JSON 文件 here。只需将其添加到您的项目中的assets 文件夹中,然后在解析后将城市和国家/地区列表添加到微调器。

【讨论】:

  • 你是怎么解析这个东西的?
  • 查看这里了解有关 JSON 解析的详细信息stackoverflow.com/questions/9605913/…
  • new Gson().fromJson(getContentFromCountryFile(), new TypeToken>>() { }.getType()) 如果其他人试图解决它。只需将此依赖项放在 gradle 中: implementation 'com.google.code.gson:gson:2.8.5'
猜你喜欢
  • 2017-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-02
  • 1970-01-01
  • 2015-04-14
  • 2011-01-21
  • 2011-06-30
相关资源
最近更新 更多