Which is the best api to retrieve all the cities in given country? I tried downloading from geonames. but it seems data is not reliable.` Is it possible to query city, along with state and country in overpass api?
Can you please suggest a better way to download cities and its points?
I have done a similar task by making use of overpass api with the help of overpy which is a python package.
Firstly I have retrieved all states of country using the query
[out:json];
area["ISO3166-1"="IN"];
(rel(area)["admin_level"="4"];);
out;
Now I have fetched all districts for each state which is admin_level=5
.
[out:json];
area["ISO3166-2"="IN-KL"];
(rel(area)["admin_level"="5"];);
out;
State ISO3166-2
is from the data received from the API.
Now you can fetch cities for each districts using the data from API.
[out:json];
area["ISO3166-2"="{0}"]["admin_level"="4"];
(rel["name"="Thiruvananthapuram"](area);)->.center;
node(around.center:10000)["place"];
out;"""
This worked for me. Remember fetching all the cities in a country is a really huge task for the OSM Servers. Fetch the data that you really need.