PHP code example of spacedealer / geonames-api

1. Go to this page and download the library: Download spacedealer/geonames-api 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/ */

    

spacedealer / geonames-api example snippets


$client = new \spacedealer\geonames\api\Geonames('your_username');
try {
    $response = $client->postalCodeSearch([
        'postalcode' => '10997',
        'country' => 'de',
    ]);

    if ($response->isOk()) {
        $count = $response->count();
        echo "Found entries: $count" . PHP_EOL;
        $placeName = $response->getPath('0/placeName');
        echo "Place name   : " . $placeName . PHP_EOL;
    } else {
        echo $response->getPath('message') . PHP_EOL;
    }
} catch (\RuntimeException $e) {
    echo $e->getMessage() . PHP_EOL;
}

php composer.phar