Z
Z
zvonok13372019-03-03 20:26:03
Mobile development
zvonok1337, 2019-03-03 20:26:03

Where to get the coordinate boundaries of cities?

Hello. The boundaries of every city in the world can be represented as a polygon. So does 2gis, for example. How to get the coordinates of the borders, so that later the application understands and determines in which city it is located by geolocation?
ps detection by IP is not used

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sadless74, 2019-03-03
@zvonok1337

To get polygons of cities from OpenStreetMap, you can use overpass-turbo.eu (site api is blocked, use VPN)
Request for the Moscow region:

[out:xml];

area
  (area.region)
  ["boundary"="administrative"]
  ["name"="Московская область"]
->.a;

(
  node
  	(area.a)
  	["place"~"city|town"];
  way
  	(area.a)
  	["place"~"city|town"];>;
  relation
  	(area.a)
  	["place"~"city|town"];>;
)->.b;
.b out meta qt;

The result can be exported to geojson. Upload this data about polygons to your database and search there.
Free server restrictions will not allow you to make a request for the whole country, continent, planet.
To do this, you need to rent a server, install the Overpass docker on it , import OpenStreetMap data for the planet or smaller parts , and already load your server with requests.
If you want to look for the nearest center of the settlement, then there is an answer to a similar question. This is the nearest neighbor problem . There are ready -made archives with coordinates of settlements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question