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

2
1

Hi,

Is the only way to use OSM Data by downloading them? There's anyway to use the data with javascript via API without the need to download Data? if yes can you provide me with any example please. Thank you

asked 04 Mar '13, 12:53

Berjawi's gravatar image

Berjawi
41113
accept rate: 0%

edited 04 Mar '13, 20:45

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


You can also use for example the overpass API to get all restaurants in a given geographic area as a JSON-formatted object, and then process this object using JavaScript. Is that what you want to do?

You would need to know the key-Value-combination(s) of your objects of interest and the lat/lon coordinates of the bounding box in which to search.

http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];node[amenity=restaurant](50.7,7.1,50.8,7.25);out;
permanent link

answered 04 Mar '13, 14:55

gormo's gravatar image

gormo
2.9k32660
accept rate: 13%

edited 04 Mar '13, 14:56

Thank you. Actually I tried this using javascript but its fail. check this code please: $(document).ready(function() { var url='http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];nodeamenity=restaurant;out;'; $('#myBtn').click(function(){ $.getJSON(url, function(data) { alert('success');}).success(function(){alert('second success');}).error(function(){alert('error');}); }); });

I dont know why the result is always error !!

(04 Mar '13, 15:48) Berjawi

you are missing square brackets [ ] around amenity=restaurant

(04 Mar '13, 16:10) gormo
1

@gormo: they were eaten by MarkDown. The code should have been written in a new line and indented by a space to display it as it is.

(04 Mar '13, 20:30) aseerel4c26 ♦
2

$.getJSON(..) needs the success function in its third argument: http://api.jquery.com/jQuery.getJSON/

The call itself and standalone returns JSON.

(05 Mar '13, 08:18) Roland Olbricht
1

Here is an Example that works for me: http://pastebin.com/rfQgCPtZ . It's using JSONP, cause I could not get pure JSON running consistently because of the same origin policies(probably).

(05 Mar '13, 14:58) gormo

Dear Berjawi, What do you mean by using OSM data ? There some protocols at the Wiki for commercial or any other use, but youre question needs some extra data to made clear whats behind your question. Take for instance a look here http://wiki.openstreetmap.org/wiki/Commercial_OSM_Software_and_Services.

permanent link

answered 04 Mar '13, 13:45

Hendrikklaas's gravatar image

Hendrikklaas
9.3k207238387
accept rate: 5%

3

Hi, thank you for you answer. Here's a sample example : I want to search all restaurant near a given location, but I'll not display the data on a map, I just want to use the data on my code, lets tell display data as text.

What I understand from the wiki , that I can use API to search and download Data to my local, then put the data into a database and finally use data in the code from my database. there's any other way?

(04 Mar '13, 13:51) Berjawi

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:

×710
×290
×230
×60
×31

question asked: 04 Mar '13, 12:53

question was seen: 12,837 times

last updated: 05 Mar '13, 14:58

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