PHP code example of maxh / php-nominatim

1. Go to this page and download the library: Download maxh/php-nominatim library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maxh / php-nominatim example snippets


use maxh\Nominatim\Nominatim;

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

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

$nominatim->find($search);

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

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

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

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

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

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

$details = $nominatim->newDetails()
            ->placeId(1234)
            ->polygon('geojson');

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

$details = $nominatim->newDetails()
            ->osmType('R')
            ->osmId(1234)
            ->polygon('geojson');

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

$nominatim = new Nominatim($url, [
    'verify' => false
]);

$result = $nominatim->find($lookup, [
    'verify' => false
]);


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);
bash
composer