PHP code example of riverside / php-nominatim
1. Go to this page and download the library: Download riverside/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/ */
riverside / php-nominatim example snippets
$client = new \Riverside\Nominatim\Client();
try {
$response = $client->search('Madison Square Garden, NY');
if ($response->isOK()) {
echo $response->getLat(0) . ", " . $response->getLng(0);
} else {
echo 'Location not found.';
}
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
$client = new \Riverside\Nominatim\Client();
try {
$response = $client->reverse(48.8539373, 2.2825966);
if ($response->isOK()) {
echo $response->getAddress(0);
} else {
echo 'Address not found';
}
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
$client = new \Riverside\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();
}
$client = new \Riverside\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();
}
$client = new \Riverside\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();
}
$client = new \Riverside\Nominatim\Client();
try {
$response = $client->deletable();
if ($response->isOK())
{
echo '<pre>';
print_r($response->toArray());
} else {
echo 'Deletable objects not found';
}
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
$client = new \Riverside\Nominatim\Client();
try {
$response = $client->polygons();
if ($response->isOK())
{
echo '<pre>';
print_r($response->toArray());
} else {
echo 'Polygons not found';
}
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
composer
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install