NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I would like know how I can get in a json output format the cities around a city.

For example:

Cities around "London" in 10 km.

I read about "around"

And querying about interest poins nearby (like cafe or bar)

But I don't know how I can fetch this.

Could be something like? For example nearby cities in Madrid in 10 km:


I am trying to achieve this for a PHP script, so I plan use a curl request with the OverPass API.

asked 28 Feb '16, 00:09

shakaran's gravatar image

accept rate: 0%

When working with Overpass API, it's good to use Overpass turbo (a web-IDE written around Overpass API) to test your queries.

Overpass turbo will also give you error messages

Now, for the actual question. First you need to create the input set of the "around" command (or you need to know the coordinates you want to query around). That depends a bit on the place you want to query. Some names are used for a lot of different places, so finding a good selector for it is crucial

In the example of Madrid, you will see that there are 22 places called Madrid, while there's only one city called Madrid. Compare the following two queries in Overpass Turbo:



When you have found a good selector (based on tags or any other criterium Overpass can handle), you need to save that point into a set, let's call the set "center":


Now that you have the central node, you can use the around command to query everything around Madrid, like this:


But this will query every single object in that area (and will probably be too big for your browser to handle). So then you need to filter the results further with other filters. F.e. related to your query, all places near Madrid (cities are usually further apart than 10km, so that wouldn't yield any results).

So the full query looks like this.


And when you execute the query, you'll see the results:

When you're finished, you can use one of the export functions of Overpass Turbo to get it formatted as a nice URL (without useless whitespace and with fully escaped special characters).

permanent link

answered 29 Feb '16, 13:09

Sanderd17's gravatar image

accept rate: 31%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 28 Feb '16, 00:09

question was seen: 7,756 times

last updated: 29 Feb '16, 13:09

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum