views:

358

answers:

2

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?

+4  A: 

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.

ire_and_curses
+1  A: 

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

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

Igor Shubovych
Is CloudMade free or requires a commercial contract for production usage?
Robert Mircea
From the FAQ:Q: Is anyone allowed to sell and make money from OpenStreetMap?A: All of the data in OpenStreetMap is licensed for use by the individual contributors under the terms of the Creative Commons Attribution Share Alike 2.0 License. The terms of the license allow anyone to re-use the data in any way, so long as they give appropriate attribution. This includes the right to re-sell the data, so yes, anyone can make money from OpenStreetMap.
casper