2017 © Pedro Peláez
 

library element-geocoding

GiBiLogic Elements - Geocoding

image

gibilogic/element-geocoding

GiBiLogic Elements - Geocoding

  • Tuesday, March 28, 2017
  • by gibilogic
  • Repository
  • 3 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 125 % Grown

The README.md

GiBiLogic "Elements" library

Often we find ourselves writing the same code for different projects, over and over again., (*1)

We got bored, so we decided to collect all these bits and pieces of code in ready-to-use packages., (*2)

Geocoding Element

This package contains useful classes for working with geographical coordinates., (*3)

It uses Google's geocoding service; you can find more informations on its official documentation., (*4)

Installation

Add this package to the composer.json of your application with the console command:, (*5)

composer require gibilogic/element-geocoding

Or, if you are using the composer.phar version, use the console command:, (*6)

php composer.phar require gibilogic/element-geocoding

Usage

Basics

Use the Point class to manage geographical points with latitude and longitude:, (*7)

$milan = new Point(45.464161, 9.190336);
$rome = new Point(41.893056, 12.482778);

Use the Route class to manage relation between two points:, (*8)

$route = new Route($milan, $rome);
$distance = $route->getDistance();

Route instances can also be compared by using the compareTo method:, (*9)

$milanRomeRoute = new Route($milan, $rome);
$milanTurinRoute = new Route($milan, $turin);

$comparison = $milanRomeRoute->compareTo($milanTurinRoute);

Use the geocodeAddress method of the GoogleGeocodeService to get a Point instance from an address:, (*10)

$point = $googleGeocodeService->geocodeAddress('via Aldo Moro 48, 25124 Brescia, Italy');

Advanced

Add and implement the GeocodeableInterface to existing classes:, (*11)

class Address implements GeocodeableInterface
{
    protected $address;
    protected $zipCode;
    protected $city;
    protected $province;

    protected $latitude;
    protected $longitude;

    // ...

    public function getAddressForGeocoding()
    {
        return sprintf('%s, %s %s (%s), Italy',
            $this->address,
            $this->zipCode,
            $this->city,
            $this->province
        );
    }

    public function getCoordinates()
    {
        return new Point($this->latitude, $this->longitude);
    }

    public function setCoordinates(Point $point)
    {
        $this->latitude = $point->getLatitude();
        $this->longitude = $point->getLongitude();
    }
}

Then use the geocode method of the GoogleGeocodeService:, (*12)

$point = $googleGeocodeService->geocode($address);

Contributions

You can contribute to the growth of this library in a lot of different ways:, (*13)

  • Create an issue about a bug or a feature you would like to see implemented
  • Open pull requests about fixes, new features, tests, documentation, etc.
  • Use the library and let us know ;)

License

See the attached license file., (*14)

The Versions

28/03 2017

dev-master

9999999-dev http://www.gibilogic.com

GiBiLogic Elements - Geocoding

  Sources   Download

MIT