adityamenon / postcodes-io-laravel by adityamenon

59
4
3
Package Data
Maintainer Username: adityamenon
Maintainer Contact: hello@adityamenon.co (aditya menon)
Package Create Date: 2014-11-20
Package Last Update: 2015-12-07
Language: PHP
License: MIT
Last Refreshed: 2024-11-24 03:00:23
Package Statistics
Total Downloads: 59
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 4
Total Watchers: 3
Total Forks: 7
Total Open Issues: 2

ABANDONED

Sorry, if you've come here looking for updates, I regret to inform that this package has now been abandoned. Please ping me @codeisawesome on twitter if you need something urgent to updated here. Forking and updating it, however, is a better idea.

PostcodesIo Laravel Package

Build Status

A laravel package for querying the postcodes.io web service.

Most of the Guzzle layer code was taken from @BoxUk's Symfony bundle, many props!

License

Installation

Installation is handled via Composer.

  1. Run the following command:

    $ composer require adityamenon/postcodes-io ~1.0
    

    This should add the following to your project's composer.json file:

    "require": {
        "adityamenon/postcodes-io": "~1.0"
    }
    
  2. Add the Service Provider to your app/config/app.php file:

    'providers' => array('Adityamenon\PostcodesIo\PostcodesIoServiceProvider')
    
  3. Add the Facade in the same file:

    'aliases' => array('PostcodesIo' => 'Adityamenon\PostcodesIo\Facade')
    

Usage

Use the PostcodesIo facade with any of the methods below to get data from the service. For example: PostcodesIo::lookup('CF10 1DD').

Methods

lookup()

API documentation

Lookup data about a particular postcode.

Parameters:

  • postcode (Required): The postcode.

Example:

$response = $client->lookup(array('postcode' => 'CF10 1DD'));

bulkLookup()

API documentation

Lookup data about a set of postcodes.

Parameters:

  • postcodes (Required): An array of postcodes (max 100).

Example:

$response = $client->bulkLookup(array('postcodes' => array('CF10 1DD', 'W1B 4BD'));

reverseGeocode()

API documentation

Get data for postcodes nearest a given latitude/longitude coordinate.

Parameters:

  • latitude (Required): The latitude.
  • longitude (Required): The longitude.
  • limit (Optional): The maximum number of postcodes to return (default 10, max 100).
  • radius (Optional): The radius in metres in which to find postcodes (default 100, max 1000).

Example:

$response = $client->reverseGeocode(array('latitude' => 51.481667, 'longitude' => -3.182155);

bulkReverseGeocode()

API documentation

Bulk translation of latitude/longitude coordinates into postcode data.

Parameters:

  • geolocations (Required): The geolocations to look up (maximum 100). This parameter should be an array, each element with the following keys:

    • latitude (Required): The latitude.
    • longitude (Required): The longitude.
    • limit (Optional): The maximum number of postcodes to return (default 10, max 100).
    • radius (Optional): The radius in metres in which to find postcodes (default 100, max 1000).

Example:

$response = $client->bulkReverseGeocode(
    array(
        'geolocations' => array(
            array('latitude' => 51.481667, 'longitude' => -3.182155),
            array('latitude' => 51.88328, 'longitude' => -3.43684, 'limit' => 5, 'radius' => 500)
        )
    )
);

matching()

API documentation

Find postcodes matching a given query.

Parameters:

  • query (Optional): The postcode query, e.g. 'CF10'.
  • limit (Optional): The maximum number of postcodes to return (default 10, max 100).

Example:

$response = $client->matching(array('query' => 'CF10', 'limit' => 20);

validate()

API documentation

Validate a postcode.

Parameters:

  • postcode (Required): The postcode to validate.

Example:

$response = $client->validate(array('postcode' => 'CF10 1DD');

autocomplete()

API documentation

Get a list of postcodes to autocomplete a partial postcode.

Parameters:

  • postcode (Required): The postcode to autocomplete.
  • limit (Optional): The maximum number of postcodes to return (default 10, max 100).

Example:

$response = $client->autocomplete(array('postcode' => 'CF10', 'limit' => 20);

random()

API documentation

Get data for a random postcode.

Parameters: None.

Example:

$response = $client->random();

outwardCodeLookup()

API documentation

Get data for the specified "outward code" (first half of postcode).

Parameters:

  • outcode (Required): The outward code (first half of postcode) to get location data for.

Example:

$response = $client->outwardCodeLookup(array('outcode' => 'CF10');