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

can anyone show an example of how to use search on the osm from your application - ie not to open nominatim page.

asked 04 Nov '10, 09:52

Artem%20Bolshakov's gravatar image

Artem Bolshakov
15222
accept rate: 0%


Nominatim works with URL's. You can find many examples on the wiki at:
http://wiki.openstreetmap.org/wiki/Nominatim

You already asked the same question here. Once you read the specification, you have to adapt your code to handle URL's requests and returned XML data. This depends on your development/application and the question is not anymore specific to OSM and shouldn't be posted here. You might give a last try by asking on the OSM developers list ("dev"), see the details in the wiki.

permanent link

answered 04 Nov '10, 13:34

Pieren's gravatar image

Pieren
9.8k2083157
accept rate: 15%

edited 04 Nov '10, 14:51

ok, thanks.

(04 Nov '10, 15:25) Artem Bolshakov

here is an example i've beenplaying with, this is using codeigniter

$xml->open('http://nominatim.openstreetmap.org/search?q='.$searchstring.'&format=xml&polygon=0&addressdetails=1&countrycodes=gb');
$addrlist = $this->_xml2assoc($xml, "root");

            $data['addressescount'] = count($addrlist[0]['childs']);
            $addresses = $addrlist[0]['childs'];

            if ($data['addressescount'] == 0)
            {
                $data['addrfrommsg'] = 'Sorry, we could not find any location for this address.';
            }
            elseif (($data['addressescount'] > 0) && ($data['addressescount'] < 20))
            {
                // put each address from nominatim into an array
                foreach ($addresses as $k => $inside)
                {
                    $addrlist[$k]['place_id']= $addrlist[0]['childs'] [$k]['attr']['place_id'];
                    $addrlist[$k]['lon']= $addrlist[0]['childs'] [$k]['attr']['lon'];
                    $addrlist[$k]['lat']= $addrlist[0]['childs'] [$k]['attr']['lat'];
                    $addrlist[$k]['road_x']= $addrlist[0]['childs'] [$k]['childs'][0]['childs'][0]['text'];
                    $addrlist[$k]['city_x']= $addrlist[0]['childs'] [$k]['childs'][2]['childs'][0]['text'];
                    $addrlist[$k]['display_name']= $addrlist[0]['childs'] [$k]['attr']['display_name'];
                    $data['addrfromlist'][]=$addrlist[$k];

            // insert the location in database
                    $country = 'UK';
                    $direction = 'from';
                    $postcode = '';
                    if ($addrlist[$k]['place_id'] == 0 )
                    {
                        $addrlist[$k]['place_id'] = $k;
                    }
                    $this->locations_mdl->insert_location($data['session_id'], $addrlist[$k]['place_id'], $data['username'],
                                        $addrlist[$k]['lon'], $addrlist[$k]['lat'], $addrlist[$k]['road_x'], $addrlist[$k]['city_x'],
                                        $postcode, $country, $addrlist[$k]['display_name'], $direction);

                }
            }
            elseif ($data['addressescount'] >= 20)
            {
                $data['addrfrommsg'] = 'Sorry, too many results please refine your search.';
            }
            $xml->close();
            return $data;
    }
permanent link

answered 28 Aug '11, 09:00

jerry01's gravatar image

jerry01
1
accept rate: 0%

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

question asked: 04 Nov '10, 09:52

question was seen: 7,677 times

last updated: 28 Aug '11, 09:00

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