Skip to content
/ geocode Public

Geocode addresses within your Laravel application

License

Notifications You must be signed in to change notification settings

vhnh/geocode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VHNH

vhnh/geocode

The Vhnh Geocode package allows geocoding addresses within your Laravel application.

tests

Setup

First you'll authorize your geocoding provider. Currently this package provides a provider for "Google Maps" but writing your own providers is pretty easy.

Geocoding Addresses

The Vhnh\Geocode\Request accepts an object which implements the Vhnh\Geocode\Contracts\Address as its first argument in its constructor. Optionally you may settings the number of attemps as the second constructor parameter.

<?php

namespace App\Jobs;

use App\Address;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Vhnh\Geocode\Providers\Google\Request as GeocodeRequest;

class Geocode implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    protected $address;

    public function __construct(Address $address)
    {
        $this->address = $address;
    }

    public function handle()
    {
        $response = (
            new GeocodeRequest($this->address)
        )->handle();

        // ...
    }
}

The Response

The handle method should return Vhnh\Geocode\Contracts\Ressponse which must implement a longitude and a latitude method.

$response = $request->handle();

$address->update([
    'latitude' => $response->latitude(),
    'longitude' => $response->longitude()
]);

License

The Vhnh Geocode package is open-sourced software licensed under the MIT license.

About

Geocode addresses within your Laravel application

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages