Getting list of countries, cities and their areas/states/towns respectively [closed]
Asked Answered
A

1

10

Is this possible to load a list of all countries in a spinner, then on selecting the particular country, all of its cities appears in another spinner and after selecting the city, we get the list of areas or towns of that city in android using google-api or something like country picker? Currently i am using this to get the list of countries. but how to get their respective cities and towns?

    ArrayList<String> list=new ArrayList<String>();
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
    Locale obj = new Locale("", countryCode);
    list.add(obj.getDisplayCountry());
}
Anschluss answered 8/11, 2016 at 15:48 Comment(3)
I do this using two spinners.Feverous
I don't think Google Maps APIs can get a list of all cities in the country. These APIs don't work like database search.Noaccount
Note: This question is requesting a recommendation for an API, which is not allowed on Stack Overflow. See the help center.Methylal
I
9

You can use the JSON file available here. Just add it to your project into the assets folder and add the list of cities and countries to spinner after parsing it.

Inning answered 25/11, 2016 at 5:40 Comment(3)
How do you parse this thing?Stedman
check this out for details about JSON parsing #9606413Inning
new Gson().fromJson(getContentFromCountryFile(), new TypeToken<Map<String, List<String>>>() { }.getType()) If someone else is trying to solve it. Just put this dependency in the gradle: implementation 'com.google.code.gson:gson:2.8.5'Stedman

© 2022 - 2024 — McMap. All rights reserved.