I've trying to find a way to use the OpenStreetMap API to get a list of all cities in a specific country with their longitude, latitude for an iOS app to develop.

However I been unable to do so. I've been trying to use the Overpass API but I just can'T find the right parameters to list all cities (and not just the top 1000 or so).

Does anyone know a way to do this that returns proper JSON?

有帮助吗?

解决方案

Your query isn't (IMHO) a good one for an API, as your results are very sparse but need to run over all the data (no general indexing).

So get an OSM extact, filter it with osmosis and then do your own processing on the results.

Keep in mind, that a town can be modelled differently in OSM:

  • as tagged node e.g. place=city
  • as landuse area (also with additional place tags)
  • as boundary so, a (multipolygon)relation

You might also want to have a look at nominatim for geocoding and the legal FAQ for distributing OSM data.

其他提示

Using Overpass API.

area["ISO3166-1"="CY"]->.a1;
(
  nwr[place="city"](area.a1);
);
out body;

Link. Open console and click run to see the request and response.

Or use curl

curl 'https://lz4.overpass-api.de/api/interpreter' \
 --data-raw 'data=[out:json];area["ISO3166-1"="CY"]->.a1;
(
nwr[place="city"](area.a1);
);
out body;'

Try Overpass_API

For example, all states of Germany:

 http://overpass-api.de/api/interpreter?data=(rel[admin_level="4"](47,6,55,15););out;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top