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

I have a map inside a Confluence wiki page, and using PocketQuery I get the addresses I want to display from my DB.

What's the most direct way to do the Nominatim request and the Leaflet marker placement?

I can generate code that looks like this:

    <script>
    #foreach($person in $result)
    $.getJSON('https://nominatim.openstreetmap.org/search/$person.strasse $person.hausnummer ,$person.plz?format=json', cbMarker);
    function cbMarker(data){
      L.marker([data.lat, data.lon], {title: '$person.name'}).addTo(map);
    }
    #end
    </script>
but something is wrong, it seems to crash the template and it falls back to just showing me $result as a table.

asked 06 Nov '15, 10:13

HeaDCase's gravatar image

HeaDCase
15113
accept rate: 0%

edited 14 Nov '15, 22:08

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

1

Is Conluence supposed to be Confluence?

(14 Nov '15, 08:51) scai ♦
1

Yeah, my typo there. Got it sorted in the meantime, the suggestion about using only the first element of the returned array is right on the money. Thanks!

(14 Nov '15, 20:58) HeaDCase

Your question is difficult to understand (what is Conluence and where does PocketQuery come into it - are we supposed to know?) but your JavaScript looks like it assumes that the Nominatim response will be a hash when indeed it will be an array of search results; you probably need something like data[0].lat instead of data.lat. Which will of course fail if the result set is empty.

permanent link

answered 13 Nov '15, 23:00

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

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:

×689
×74
×28

question asked: 06 Nov '15, 10:13

question was seen: 5,625 times

last updated: 14 Nov '15, 22:08

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