PHP code example of merlindiavova / postcodesio

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

    

merlindiavova / postcodesio example snippets




declare(strict_types=1);

use PostcodesIO\API\Client;
use PostcodesIO\API\Client\ResponseCheck;
use PostcodesIO\API\Factory\Psr17Factory;
use Sunrise\Http\Client\Curl\Client as SunClient;
use Nyholm\Psr7\Factory\Psr17Factory as NyholmPsr17Factory;

tion
    )
);

$response = $postcodesIoClient->getPostcodeClient()->fetch('NW10 4DG');

$postcode = $response->getFirstResult(); // PostcodesIO\API\Postcode\Data

echo $postcode->getAdminWard() . ', ' . $postcode->getAdminDistrict(); // Harlesden, Brent


// ... 
// Returns the postcode api client
$postcodesClient = $postcodesIoClient->getPostcodeClient();

// Fetch a postcode
$response = $postcodesClient->fetch('HA0 2TF'); // Returns a Postcode\Response object
$postcode = $response->getFirstResult(); // Returns Postcode\Data object

// Fetch many postcodes
$response = $postcodesClient->fetchByBulk(['HA0 2TF', 'SE1 2UP']); // Returns a Postcode\Response object
$postcodes = $response->getResult(); // Returns Client\Collection of Postcode\Data objects

// Fetch Reverse Geocode
$response = $postcodesClient->fetchByReverseGeocode(-0.076579, 51.503378); // Returns a Postcode\Response object
$postcodes = $response->getResult(); // Returns Client\Collection of Postcode\Data objects

// you add an array of optional query parameters as the third argument
$queryParams = ['limit' => 10, 'radius' => '1000', 'wideSearch' => true];
$response = $postcodesClient->fetchByReverseGeocode(-0.076579, 51.503378, $queryParams);