Giter VIP home page Giter VIP logo

php-nominatim's Introduction

php-nominatim

A PHP client for Nominatim, the search engine for OpenStreetMap data.

Build Stable License
CI Latest Stable Version License

Installation

  • If Composer is already installed
composer require riverside/php-nominatim
  • If Composer is not installed on your system yet, you may go ahead and install it using this command line:
$ curl -sS https://getcomposer.org/installer | php

Next, add the following require entry to the composer.json file in the root of your project.

{
    "require" : {
        "riverside/php-nominatim" : "*"
    }
}

Finally, use Composer to install php-nominatim and its dependencies:

$ php composer.phar install

Loading

require __DIR__ . '/vendor/autoload.php';

Search (geocoding)

Look up a location from a textual description or address.

$client = new \Nominatim\Client();
try {
    $response = $client->search('Madison Square Garden, NY');
    if ($response->isOK()) {
        echo $response->getLat() . ", " . $response->getLng();
    } else {
        echo 'Location not found.';
    }
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Reverse geocoding

Generates an address from a latitude and longitude.

$client = new \Nominatim\Client();
try {
    $response = $client->reverse(48.8539373, 2.2825966);
    if ($response->isOK()) {
        echo $response->getAddress();
    } else {
        echo 'Address not found';
    }
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Address lookup

Query the address and other details of one or multiple OSM objects like node, way or relation.

$client = new \Nominatim\Client();
try {
    $client->setAddressDetails(1);
    $response = $client->lookup('R146656,W104393803,N240109189');
    if ($response->isOK()) {
        echo '<pre>';
        print_r($response->toArray());
    } else {
        echo 'Address not found';
    }
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Place details

Show all details about a single place saved in the database.

$client = new \Nominatim\Client();
try {
    $client->setAddressDetails(1);
    $response = $client->details(199375150);
    if ($response->isOK())
    {
        echo '<pre>';
        print_r($response->toArray());
    } else {
        echo 'Place not found';
    }
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Status

Check if the service and database is running, and when the database was last updated.

$client = new \Nominatim\Client();
try {
    $response = $client->status();
    if ($response->isOK())
    {
        echo '<pre>';
        print_r($response->toArray());
    } else {
        echo 'Status not found';
    }
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Links

php-nominatim's People

Contributors

riverside avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dexit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.