PHP code example of szhorvath / laravel-getaddress

1. Go to this page and download the library: Download szhorvath/laravel-getaddress 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/ */

    

szhorvath / laravel-getaddress example snippets


Szhorvath\GetAddress\GetAddressServiceProvider::class,

GETADDRESSIO_API_KEY=your-api-key

GETADDRESSIO_API_KEY=your-api-key

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Szhorvath\GetAddress\Facades\GetAddress;

class AddressController extends Controller
{
    public function lookup()
    {
        $result = GetAddress::lookup('S20 8JH');

        $longitude = $result->getLongitude();
        $latitude = $result->getLatitude();
        $addressList = $result->getAddresses();

        foreach ($addressList as $key => $address) {
            $line1 = $address->getLine1();
            $line2 = $address->getLine2();
            $line3 = $address->getLine3();
            $line4 = $address->getLine4();
            $town  = $address->getTown();
            $postalTown = $address->getPostalTown();
            $normalisedTown = $address->getNormalisedTown();
            $county = $address->getCounty();
            #Full address as comma separated string
            $csv = $address->toCsv();
        }

        #Or for a specific address you can pass the house number or name as second parameter
        $result = GetAddress::lookup('S20 8JH', 5);
        if ($address = $result->getAddress()) {
            $town  = $address->getTown();
        };
    }
}
bash
$ php artisan vendor:publish --provider="Szhorvath\GetAddress\GetAddressServiceProvider"
bash
$ php artisan vendor:publish --provider="Szhorvath\GetAddress\GetAddressServiceProvider"