2
1

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's gravatar image

tt40
61225
accept rate: 0%

edited 13 Sep '12, 07:50

NicolasDumoulin's gravatar image

NicolasDumoulin
3.3k42256


You can use Overpass API instead. Just replace

http://www.openstreetmap.org/api/0.6/

by

http://overpass-api.de/api/xapi?

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.

permanent link

answered 12 Sep '12, 14:07

Roland%20Olbricht's gravatar image

Roland Olbricht
6.3k35885
accept rate: 36%

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.

permanent link

answered 12 Sep '12, 09:56

NicolasDumoulin's gravatar image

NicolasDumoulin
3.3k42256
accept rate: 13%

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 ♦
Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×237
×46
×4

question asked: 12 Sep '12, 09:41

question was seen: 4,307 times

last updated: 13 Sep '12, 07:50

powered by OSQA