PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

PostcodesIO Build Status

PostcodesIO is a PHP library for postcodes.io API.

Install

Install using composer:

$ composer require jabranr/postcodes-io

Documentation

All of the following methods returnn back the same complete response as it comes from postcodes.io API in JSON format.

Find postcode information

$postcodeFinder = new PostcodesIO();

try {
  $addresses = $postcodeFinder->find('NW1 5LD');
} catch(\Exception $e) {
  echo $e->getMessage();
}

You can catch specific Jabranr\PostcodesIO\Exception\PostcodeIOException or/and catch general \Exception to catch any type.

$postcodeFinder = new PostcodesIO('NW1 5LD');
$addresses = $postcodeFinder->getResult();

Find postcode information by geo location

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->findByLocation(51.520331, -0.1396267);

Find random postcode information

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->findRandom();

OR use the alias method:

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->random();

Validate a postcode

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->validate('NW1 5LD');

Find nearest postcodes

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->findNearest('NW1 5LD');

OR use the alias method:

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->nearest();

Get an autocompleted list of a postcode/outcode

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->autocomplete('NW1');

Search a postcode

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->query('NW1 5LD');

OR use the alias method:

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->search('NW1 5LD');

Find an outcode

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->findOutcode('NW1');

Find nearest outcodes

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->nearestOutcode('NW1');

Find an outcode by location

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->findOutcodeByLocation(51.520331, -0.1396267);

Bulk postcodes search

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->bulkPostcodeSearch(array('NW1 5LD', 'W1T 7NY'));

Maximum of 100 postcodes per request.

Bulk reverse geocoding

$postcodeFinder = new PostcodesIO();
$addresses = $postcodeFinder->bulkReverseGeocoding(array(
    array(51.520331, -0.1396267),
    array(51.520331, -0.1396267)
));

Maximum of 100 geolocations per request.

License

MIT License © 2016 – Jabran Rafique