Coder Social home page Coder Social logo

postcode-lookup's Introduction

Postcode Lookup

Latest Stable Version Total Downloads Latest Unstable Version License

PHP library that performs a postcode lookup using Google Maps API.

Compatible with Laravel 5.

Quick start

First of all you need to require the package inside your composer.json file:

{
    "require": {
        "lodge/postcode-lookup": "0.4.0"
    }
}

Note: for Laravel 4 use version 0.3.0

Register with Laravel

Register the service provider. Inside your app.php config file add:

'providers' => array(
	...
	'Lodge\Postcode\PostcodeServiceProvider',
)

A facade is also provided, so in order to register it add the following to your app.php config file:

'aliases' => array(
	...
	'Postcode' => 'Lodge\Postcode\Facades\Postcode',
);

Publish the configuration file.

php artisan vendor:publish --provider="Lodge\Postcode\PostcodeServiceProvider"

Set your Google API key inside config/postcode.php file.

Usage with Laravel

From within your controller you can call:

	$postcode = Postcode::lookup('SW3 4SZ');

	print_r($postcode);

	// Outputs
	array(
		'postcode'      => 'SW34SZ',
		'street_number' => '',
		'street'        => '',
		'sublocality'   => '',
		'town'          => 'London',
		'county'        => 'Greater London',
		'country'       => 'United Kingdom',
		'latitude'      => 51.489117499999999,
		'longitude'     => -0.1579016
	);

Get the Latitude and Longitude of an address

	$coordinates = Postcode::getCoordinates($address);

	print_r($coordinates);

	// Outputs
	array(
		'latitude'  => 1.521231
		'longitude' => -23.012123
	)

Usage outside of Laravel

	// First of all you need to instantiate the class
	// And assuming that you have required the composer
	// autoload.php file
	require 'vendor/autoload.php';

    $googleApiKey = 'your-google-api-key';
	$postcode = new Lodge\Postcode\Postcode($googleApiKey);
	$results = $postcode->lookup('SW3 4SZ');

	print_r($results);

	// Outputs
	array(
		'postcode'      => 'SW34SZ',
		'street_number' => '',
		'street'        => '',
		'sublocality'   => '',
		'town'          => 'London',
		'county'        => 'Greater London',
		'country'       => 'United Kingdom',
		'latitude'      => 51.489117499999999,
		'longitude'     => -0.1579016
	)

If you need to get just the latitude and longitude for an address you can use:

    $googleApiKey = 'your-google-api-key';
	$postcode = new Lodge\Postcode\Postcode($googleApiKey);
	$results = $postcode->getCoordinates('SW3 4SZ');

	print_r($results);

	// Outputs
	array(
		'latitude'  => 51.489117499999999
		'longitude' => -0.1579016
	)

Changelog

  • Version 0.4

    • Added configuration file and the ability to set the Google API key.
    • Updated namespaces to PSR-4
    • Added test stubs.
    • Dropped support for Laravel 4.
  • Version 0.3

    • Removed deprecated bind call and instantiate as a singleton instead.
  • Version 0.2

    • Laravel 5 compatible
    • Fixed facade namespace, that would not adhere to PSR-0
    • Updated documentation
  • Version 0.1

    • Initial Release

License

The MIT License (MIT)

Copyright (c) 2013-2015 Dan Ursu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

postcode-lookup's People

Contributors

daursu avatar sjelfull avatar agordn52 avatar warksit avatar alphamarket avatar stevenbullen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.