opendi/nominatim

A simple interface to OSM Nominatim search.

1.0.0 2018-01-22 13:48 UTC

This package is not auto-updated.

Last update: 2024-12-21 17:38:14 UTC


README

A simple interface to OSM Nominatim search.

Latest Stable Version Total Downloads Build Status License

See Nominatim documentation for info on the service.

Basic usage

Create a new instance of Nominatim by using the newInstance() factory method.

use Opendi\Nominatim\Nominatim;

$url = "http://nominatim.openstreetmap.org/";
$nominatim = Nominatim::newInstance($url);

Searching by query:

$search = $nominatim->newSearch();
$search->query('1600 Pennsylvania Ave NW, Washington, DC 20500, United States');

$nominatim->find($search);

Or break it down by address:

$search = $nominatim->newSearch()
    ->street('1600 Pennsylvania Ave NW')
    ->city('Washington')
    ->county('Washington')
    ->state('Washington DC')
    ->postalCode('DC 20500')
    ->country('United States')
    ->addressDetails();

$nominatim->find($search);

The result will be an array of results (in this case, only one result was found).

Array
(
    [0] => Array
        (
            [place_id] => 2632584431
            [licence] => Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
            [osm_type] => way
            [osm_id] => 238241022
            [boundingbox] => Array
                (
                    [0] => 38.8974898
                    [1] => 38.897911
                    [2] => -77.0368539
                    [3] => -77.0362521
                )

            [lat] => 38.8976989
            [lon] => -77.036553192281
            [display_name] => The White House, 1600, Pennsylvania Avenue Northwest, Thomas Circle, Southwest Waterfront, Washington, 20500, United States of America
            [class] => tourism
            [type] => attraction
            [importance] => 1.5576757387296
            [icon] => http://nominatim.openstreetmap.org/images/mapicons/poi_point_of_interest.p.20.png
            [address] => Array
                (
                    [attraction] => The White House
                    [house_number] => 1600
                    [pedestrian] => Pennsylvania Avenue Northwest
                    [neighbourhood] => Thomas Circle
                    [suburb] => Southwest Waterfront
                    [city] => Washington
                    [county] => Washington
                    [postcode] => 20500
                    [country] => United States of America
                    [country_code] => us
                )

        )

)