PHPackages                             phil/geolocation-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phil/geolocation-bundle

AbandonedArchivedSymfony-bundle[Utility &amp; Helpers](/categories/utility)

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.

0.5.2(11y ago)127953[1 issues](https://github.com/ph-il/geolocation-bundle/issues)MITPHPPHP &gt;=5.4.21

Since May 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ph-il/geolocation-bundle)[ Packagist](https://packagist.org/packages/phil/geolocation-bundle)[ Docs](https://github.com/ph-il/geolocation-bundle)[ RSS](/packages/phil-geolocation-bundle/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (14)Versions (21)Used By (0)

Phil GeolocationBundle
======================

[](#phil-geolocationbundle)

NOT UPDATED... Working on the new version for Symfony 3. Divided in different Bundles

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.

[![Latest Stable Version](https://camo.githubusercontent.com/bdf61004b9faa69abbc4b9f59141d3988db99d9528a864a2babbeeb82dd17387/68747470733a2f2f706f7365722e707567782e6f72672f7068696c2f67656f6c6f636174696f6e2d62756e646c652f762f737461626c652e706e67)](https://packagist.org/packages/phil/geolocation-bundle)[![Total Downloads](https://camo.githubusercontent.com/4567d279308217beb9641bcbb7268486d0f77f9ca3bcae9662af17566d01d09f/68747470733a2f2f706f7365722e707567782e6f72672f7068696c2f67656f6c6f636174696f6e2d62756e646c652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/phil/geolocation-bundle)[![License](https://camo.githubusercontent.com/c0e49f6770983a0e36a914607a6462517ed8410f31098f17f70c06a3e3c5ee16/68747470733a2f2f706f7365722e707567782e6f72672f7068696c2f67656f6c6f636174696f6e2d62756e646c652f6c6963656e73652e706e67)](https://packagist.org/packages/phil/geolocation-bundle)[![Build Status](https://camo.githubusercontent.com/f7fa7f0cdf1c529da69d373a99e9299b2b85ac407ac12f6292575db8c947e5e3/68747470733a2f2f7472617669732d63692e6f72672f70682d696c2f67656f6c6f636174696f6e2d62756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/ph-il/geolocation-bundle)[![Coverage Status](https://camo.githubusercontent.com/faf3b3d0dddd3312a43e5f2441fcd5d820c96db8993bab8331678eb12f278a08/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f70682d696c2f67656f6c6f636174696f6e2d62756e646c652f62616467652e706e67)](https://coveralls.io/r/ph-il/geolocation-bundle)[![SensioLabsInsight](https://camo.githubusercontent.com/17ef0a650ba07e1a52367a628c25b5a7447fc84c7fdf53134f8aeef8706fec69/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66623364316533332d346333612d346163652d626266622d3261623139316639313434622f6d696e692e706e67)](https://insight.sensiolabs.com/projects/fb3d1e33-4c3a-4ace-bbfb-2ab191f9144b)

1 Installation
==============

[](#1-installation)

1.1 Composer
------------

[](#11-composer)

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

```

or

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

```

1.2 Enable the bundle
---------------------

[](#12-enable-the-bundle)

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

```

1.3 Register the Doctrine functions you need
--------------------------------------------

[](#13-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](http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html) for details.

```
```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
----------------------

[](#14-update-your-schema)

```
doctrine:schema:update

```

2 Usage
=======

[](#2-usage)

2.1 Entities
------------

[](#21-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.

Address is independent of any other entities.

2.2 Formatter
-------------

[](#22-formatter)

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

```

### Flags

[](#flags)

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

...

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

```

### Available flags

[](#available-flags)

`FLAG_NOBR` No linebreak will be added

`FLAG_HTML` Outputs the address in html format

`FLAG_NOCASE` No case change will be applied

### 2.3 Twig extension

[](#23-twig-extension)

```
{{ address|address()|raw }}

```

This will output the formatted address, with the `FLAG_HTML` added by default

2.4 Geocoding
-------------

[](#24-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.

2.5 Import geographical data
----------------------------

[](#25-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.

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

[](#for-postal-code-by-country-data-from-geonamesorg)

Go to  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`.

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

```
// 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)

[](#for-postal-code-by-country-your-own-data--example-available-in-datafixturesdata)

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

```
// 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.

```
# 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"

3 Thanks
========

[](#3-thanks)

Some idea are taken from [padam87/address-bundle](https://packagist.org/packages/padam87/address-bundle)[craue/geo-bundle](https://github.com/craue/CraueGeoBundle)

4 TODO
======

[](#4-todo)

There is a lot to do :

- Finish all testing
- More documentations
- Clean Up Code
- All all require Entities for Geolocation

Fill free to send some corrections and suggestions.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

20

Last Release

4147d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef4519e787b0e7b195d93d2f70f62fb1d811e06ef8b65389a24aed2e8abeb12b?d=identicon)[phil](/maintainers/phil)

---

Top Contributors

[![ph-il](https://avatars.githubusercontent.com/u/80009?v=4)](https://github.com/ph-il "ph-il (36 commits)")

---

Tags

bundlegeographic-dataphpsymfonysymfony-bundleunmaintainedgeocodinggeoipaddressSymfony2geocodegeo-location

### Embed Badge

![Health badge](/badges/phil-geolocation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/phil-geolocation-bundle/health.svg)](https://phpackages.com/packages/phil-geolocation-bundle)
```

###  Alternatives

[anime-db/anime-db

The application for making home collection anime

252.1k2](/packages/anime-db-anime-db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
