This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

nominatim search

-1

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%


2 Answers:

2

Nominatim works with URL's. You can find many examples on the wiki at:
https://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.

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

0

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;
    }

answered 28 Aug '11, 09:00

jerry01's gravatar image

jerry01
1
accept rate: 0%

Source code available on GitHub .