Skip to content
📡 Wrapper for Nominatim API
PHP
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Migration PHP 5.x to PHP 7.x Mar 26, 2018
examples Migration Guzzle May 26, 2018
src Upgrade format for the new version 3.2.0 Aug 27, 2018
tests
.editorconfig Migration PHP 5.x to PHP 7.x Mar 26, 2018
.gitattributes
.gitignore Edit .gitignore Jul 9, 2018
.insight.yml
.php_cs Optimisation PHP May 24, 2018
.scrutinizer.yml Compatibility PHPUnit & CodeSniffer Feb 4, 2017
.travis.yml Migration PHP 5.x to PHP 7.x Mar 26, 2018
CODE_OF_CONDUCT.md
CONTRIBUTING.md Add community file Oct 10, 2017
ISSUE_TEMPLATE.md Add community file Oct 10, 2017
LICENSE
PULL_REQUEST_TEMPLATE.md Add community file Oct 10, 2017
README.md
composer.json
grumphp.yml Optimisation PHP May 24, 2018
phpunit.xml

README.md

Wrapper Nominatim API

Latest Stable Version Build Status Scrutinizer Code Quality Total Downloads Join the chat at https://gitter.im/maxhelias/php-nominatim MIT licensed

SensioLabsInsight

A simple interface to OSM Nominatim.

See Nominatim documentation for info on the service.

See the PhpDoc of the project.

Installation

Install the package through composer:

composer require maxh/php-nominatim

Make sure, that you include the composer autoloader somewhere in your codebase.

Basic usage

Create a new instance of Nominatim.

use maxh\Nominatim\Nominatim;

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

Searching by query :

$search = $nominatim->newSearch();
$search->query('HelloWorld');

$nominatim->find($search);

Or break it down by address :

$search = $nominatim->newSearch()
            ->country('France')
            ->city('Bayonne')
            ->postalCode('64100')
            ->polygon('geojson')    //or 'kml', 'svg' and 'text'
            ->addressDetails();

$result = $nominatim->find($search);

Or do a reverse query :

$reverse = $nominatim->newReverse()
            ->latlon(43.4843941, -1.4960842);

$result = $nominatim->find($reverse);

Or do a lookup query :

$lookup = $nominatim->newLookup()
            ->format('xml')
            ->osmIds('R146656,W104393803,N240109189')
            ->nameDetails(true);

$result = $nominatim->find($lookup);

By default, the output format of the request is json and the wrapper return a array of results. It can be also xml, but the wrapper return a object SimpleXMLElement

How to override request header ?

There are two possibilities :

  1. By Nominatim instance, for all request :
$nominatim = new Nominatim($url, [
    'verify' => false
]);
  1. By find method, for a request :
$result = $nominatim->find($lookup, [
    'verify' => false
]);

How to customize HTTP client configuration ?

You can inject your own HTTP client with your specific configuration. For instance, you can edit user-agent and timeout for all your requests

<?php
use maxh\Nominatim\Nominatim;
use GuzzleHttp\Client;

$url = "http://nominatim.openstreetmap.org/";
$defaultHeader = [
    'verify' => false,
    'headers', array('User-Agent' => 'api_client')
];

$client = new Client([
    'base_uri'           => $url,
    'timeout'            => 30,
    'connection_timeout' => 5,
]);

$nominatim = new Nominatim($url, $defaultHeader, $client);

Note

This projet was inpired by the Opendi/nominatim project with more features like reverse query, support of the xml format, customize HTTP client and more on which i work.

Recall Usage Policy Nominatim

If you use the service : http://nominatim.openstreetmap.org/, please see Nominatim usage policy.

You can’t perform that action at this time.