OSM has an API to query data. Like this: http://www.openstreetmap.org/api/0.6/map?bbox=7.012854,51.450317,7.016477,51.452105 However, you can't do this query from javascript, because this would violate the "cross-domain policy". If I understood it right, OSM could remove this policy by adding these HTTP headers to the API answer: response['Access-Control-Allow-Origin'] = "*" response['Access-Control-Allow-Methods'] = "POST, GET, OPTIONS" response['Access-Control-Allow-Headers'] = "X-Requested-With" (Taken from Stackoverflow-question "Cross domain POST query using Cross-Origin Resource Sharing getting no data back") My questions: 1. Is this limitation (as it currently is) intentional? 2. Would be possible for you to add these headers to support js queries? (Please?) asked 12 Sep '12, 09:41 tt40 NicolasDumoulin |
You can use Overpass API instead. Just replace
by
So you get e.g. http://overpass-api.de/api/xapi?map?bbox=7.012854,51.450317,7.016477,51.452105 Overpass API sets a cross-origin header. The rationale behind this is that the OSM main API is for editing, not for data reading. By contrast, the mirrors (one of which is Overpass API) serve beside a small time lag the same data, are intended for read only operations, and usually answer much faster. answered 12 Sep '12, 14:07 Roland Olbricht Perfect!!!!!!
(12 Sep '12, 14:10)
tt40
|
I don't know anything about this headers features and if they can be fixed in the HTTP response. But, there is a classical workaround: you can put a proxy script (php or python for example( on your webserver that will download the data and serve it locally. You can find some examples on the web, like mine. answered 12 Sep '12, 09:56 NicolasDumoulin Good point, I should have thought of that myself. Do I need a registration or API key? I don't want to be blocked suddenly if I do too many queries... Nevertheless: If anybody knows the answers to the original questions, I'd still be interested to solve this without a proxy. Might be useful for other JS developers, too.
(12 Sep '12, 10:01)
tt40
There is an API usage policy - it's the usual issue of shared resources. Depending on what you actually want to do, there may well be better alternatives to hitting the API directly.
(12 Sep '12, 11:02)
SomeoneElse ♦
|
In 2021, the OSM API is setting CORS header! For example:
answered 02 Apr '21, 08:03 darthwalsh |