A php API client for the methods at postcodes.io
- useful for UK postcode validation and reverse geocoding: that is, determining postcode from lat, long coordinates.
No fiddling around with api keys or authentication necessary...
With thanks to https://postcodes.io
Via Composer
$ composer require codescheme/uk-postcodes
Return data for a given postcode
use Codescheme\Ukpostcodes\Postcode;
$client = new Postcode();
$results = $client->postcodeLookup('SE21 8JL');
if ($results->status === 200) {
print_r($results);
}
->validate('SE31 9AX'); //returns boolean
->postcodeLookup('SE21 8JL');
->nearest('SE21 8JL');
->reverseGeocode(-0.397913, 51.44015); // lng,lat
->autocomplete('RG1 3');
->outcodeLookup('SE21');
$postcodes = ['OX49 5NU', 'M32 0JG', 'NE30 1DP'];
->postcodeLookupBulk($postcodes);
$coordinates = [
['longitude' => 0.629834723775309, 'latitude' => 51.7923246977375],
['longitude' => -2.49690382054704, 'latitude' => 53.5351312861402]
];
->reverseGeocodeBulk($coordinates);
$ composer test
The MIT License (MIT). Please see License File for more information.