2017 © Pedro Peláez
 

symfony-bundle geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

image

phil/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  • Wednesday, February 8, 2017
  • by phil
  • Repository
  • 1 Watchers
  • 11 Stars
  • 792 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

Phil GeolocationBundle

NOT UPDATED... Working on the new version for Symfony 3. Divided in different Bundles, (*1)

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project., (*2)

Latest Stable Version Total Downloads License Build Status Coverage Status SensioLabsInsight, (*3)

1 Installation

1.1 Composer

```
"require": {
    ....
    "phil/geolocation-bundle": "~0.2"
},
```

or, (*4)

```
php composer.phar require phil/geolocation-bundle
```

1.2 Enable the bundle

```php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Phil\GeolocationBundle\PhilGeolocationBundle(),
    );
}
```

1.3 Register the Doctrine functions you need

You need to manually register the Doctrine functions you want to use. See http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html for details., (*5)

```yaml
# in app/config/config.yml

doctrine:
    dbal:
        types:
            point: Phil\GeolocationBundle\ORM\PointType
        connections:
            default:
                mapping_types: { point: point }
    orm:
        dql:
            numeric_functions:
                POINTSTR: Phil\GeolocationBundle\ORM\PointStr
                DISTANCE: Phil\GeolocationBundle\ORM\Distance
```

1.4 Update Your schema

doctrine:schema:update

2 Usage

2.1 Entities

You can create a relation to one of the Entities, or you can use one of the traits. You can use interfaces, you need AddressInterface and GeocodeInterface. AddressableEntity and GeocodableEntity are the traits for those interface., (*6)

Address is independent of any other entities., (*7)

2.2 Formatter

```php
$formatted = $this->get("padam87.address.formatter")->format($address);

Flags

```php
use Phil\GeolocationBundle\Service\FormatterService;

...

$formatted = $this->get("phil.geolocation.address.formatter")->format($address, FormatterService::FLAG_NOBR);
```

Available flags

FLAG_NOBR No linebreak will be added, (*8)

FLAG_HTML Outputs the address in html format, (*9)

FLAG_NOCASE No case change will be applied, (*10)

2.3 Twig extension

{{ address|address()|raw }}

This will output the formatted address, with the FLAG_HTML added by default, (*11)

2.4 Geocoding

```php
use Phil\GeolocationBundle\Entity\Address;

...

$address = new Address();
```

The listener will take care of the rest ;). If you're using you own entity (without using traits) you'll need those two interfaces: AddressInterface and GeocodeInterface., (*12)

2.5 Import geographical data

This is probably the most annoying step: Storing all geographical data with their geographical positions for the countries you need. Fortunately, it's not that hard to get this information and import it into your database., (*13)

For Postal Code By Country (data from geonames.org)

Go to http://download.geonames.org/export/zip/ and download the archives for the countries you need. Let's just take DE.zip. Unzip the included DE.txt file, e.g. to /tmp/DE.txt., (*14)

Create a fixture class (in a separate folder to be able to load only this one) which extends the provided base class:, (*15)

// MyCompany/MyBundle/Doctrine/Fixtures/PhilGeolocation/MyGeonamesPostalCodeData.php
namespace MyCompany\MyBundle\Doctrine\Fixtures\PhilGeolocation;

use Phil\GeolocationBundle\DataFixtures\ORM\loadPostalCodeData;
use Doctrine\Common\Persistence\ObjectManager;

class MyGeonamesPostalCodeData extends loadPostalCodeData {

    public function load(ObjectManager $manager) {
        $this->clearPostalCodesTable($manager);
        $this->addEntries($manager, '/tmp/DE.txt', loadPostalCodeData::FORMAT_GEONAMES);
    }

}

For Postal Code By Country (your own data : example available in DataFixtures/data)

Create a fixture class (in a separate folder to be able to load only this one) which extends the provided base class:, (*16)

// MyCompany/MyBundle/Doctrine/Fixtures/PhilGeolocation/MyGeonamesPostalCodeData.php
namespace MyCompany\MyBundle\Doctrine\Fixtures;

use Phil\GeolocationBundle\DataFixtures\ORM\loadPostalCodeData;
use Doctrine\Common\Persistence\ObjectManager;

class MyGeonamesPostalCodeData extends loadPostalCodeData {

    public function load(ObjectManager $manager) {
        $this->clearPostalCodesTable($manager);
        $this->addEntries($manager, '/tmp/postalcode.csv', loadPostalCodeData::FORMAT_CSV);
    }

}

Now, backup your database! Don't blame anyone else for data loss if something goes wrong. Then import the fixture and remember to use the --append parameter., (*17)

# in a shell
php app/console doctrine:fixtures:load --append --fixtures="src/MyCompany/MyBundle/DataFixtures/ORM"

sf doctrine:fixtures:load --append --fixtures="src/Phil/TestBundle/DataFixtures/ORM", (*18)

3 Thanks

Some idea are taken from padam87/address-bundle craue/geo-bundle, (*19)

4 TODO

There is a lot to do : * Finish all testing * More documentations * Clean Up Code * All all require Entities for Geolocation, (*20)

Fill free to send some corrections and suggestions., (*21)

The Versions

08/02 2017

dev-master

9999999-dev https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

09/01 2015

0.5.2

0.5.2.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

06/01 2015

0.5.1

0.5.1.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

06/01 2015

0.5.0

0.5.0.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

11/12 2014

0.4.2

0.4.2.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

04/12 2014

0.4.1

0.4.1.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

27/11 2014

0.4.0

0.4.0.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

25/11 2014

0.3.6

0.3.6.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

14/11 2014

0.3.5

0.3.5.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

14/11 2014

0.3.4

0.3.4.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

14/10 2014

0.3.3

0.3.3.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

09/10 2014

0.3.2

0.3.2.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

09/10 2014

0.3.1

0.3.1.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

08/10 2014

0.3.0

0.3.0.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

07/10 2014

0.2.4

0.2.4.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

06/10 2014

0.2.3

0.2.3.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

10/09 2014

0.2.2

0.2.2.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

09/06 2014

0.2.1

0.2.1.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

06/06 2014

0.2.0

0.2.0.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

13/05 2014

0.1.1

0.1.1.0 https://github.com/ph-il/geolocation-bundle

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip geocoding address symfony2 geocode geo location

09/05 2014

0.1.0

0.1.0.0 https://github.com/ph-il/symfony-secure-lte

A Symfony2 Bundle to handle geographic location. Add geolocation to your entities. Add address entities. Add user geo location. Add doctrine functions for calculating geographical distances in your project.

  Sources   Download

MIT

The Requires

 

geoip geocoding address symfony2 geocode geo location