Question

Is there any API for OpenStreetMap which allows me to obtain a list of POIs within a certain distance (e.g. 10 miles) from a reference location?

Was it helpful?

Solution

Yes. The Overpass API has an "Around" feature which does exactly this (search for items within a radius of the given point). You can combine that with other requirements (eg to get a list of a particular item type):

http://wiki.openstreetmap.org/wiki/Overpass_API#Around

For example using OverPass Turbo Api (List all towns near of "Manzanares, Spain" with latitude and longitude with a radius of 150 Km, try it live!):

<osm-script output="json" timeout="25">
  <id-query {{nominatimArea:Spain}} into="area"/>
  <query type="node">
    <has-kv k="place" modv="" v="town"/>
  <around lat="38.996507" lon="-3.371946" radius="150000"/>
</query>

  <print e="" from="_" geometry="skeleton" limit="" mode="body" n="" order="id" s="" w=""/>
</osm-script>

OTHER TIPS

As far as I know, the API doesn't support this directly. The simplest approach is to select a (quasi-)rectangular bounding box that your circle fits into, and use this to retrieve your POIs. Then you can do a distance calculation to each point of interest, and discard those that exceed your radius. This will remove the small fraction of POIs that lie close to the corners of the box, and so aren't within your circle. You want to do it in this order so that you only have to do the distance calculation on a relatively small number of target locations.

Don't forget that the bounding box is defined by lat/long corners, so it isn't truly rectangular. Longitude lines converge at the poles, so the top of your box is not the same width as the bottom. How much this affects you depends on how close you are to a pole (a degree of long ~= (40000km / 360) * cos (lat)).

If you don't require supreme accuracy, then you calculate your distances using Pythagoras's theorem, remembering the cosine variation in longitude, and the factor 2 unit difference (360 degrees of longitude, but only 180 of latitude). If you do require accuracy, then you're into the realms of spherical trigonometry, and also need to consider the ellipsoidal earth. Here's an online calculator, complete with equations and open source code, that is helpful in this regard.

Here is documentation: http://developers.cloudmade.com/wiki/geocoding-http-api/Documentation

Here is example of what you need - HTML, JSON.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top