PHP code example of lodge / postcode-lookup

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

    

lodge / postcode-lookup example snippets


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

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

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

	$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
	);

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

	print_r($coordinates);

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


	// First of all you need to instantiate the class
	// And assuming that you have 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
	)

    $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
	)