<commit_before>BazingaGeocoderBundle
=====================

[![Build
Status](https://secure.travis-ci.org/willdurand/BazingaGeocoderBundle.png)](http://travis-ci.org/willdurand/BazingaGeocoderBundle)

Integration of the [**Geocoder**](http://github.com/willdurand/Geocoder) library
into Symfony2.


Installation
------------

Using Composer, just add the following configuration to your `composer.json`:

```json
{
    "require": {
        "willdurand/geocoder-bundle": "*"
    }
}
```

Register the bundle in `app/AppKernel.php`:

    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new Bazinga\Bundle\GeocoderBundle\BazingaGeocoderBundle(),
        );
    }


Usage
-----

This bundle registers a `bazinga_geocoder.geocoder` service which is an instance
of `Geocoder`. You'll be able to do whatever you want with it.

#### Killer Feature ####

You can fake the `REMOTE_ADDR` HTTP parameter through this bundle in order to get
information in your development environment, for instance:

``` php
<?php

// ...

    /**
     * @Template()
     */
    public function indexAction()
    {
        // Retrieve information from the current user (by its IP address)
        $result = $this->geocoder
            ->using('yahoo')
            ->geocode($this->getRequest()->server->get('REMOTE_ADDR'));

        // Find the 5 nearest objects from the current user.
        $objects = ObjectQuery::create()
            ->filterByDistanceFrom($result->getLatitude(), $result->getLongitude(), 15)
            ->limit(5)
            ->find();

        return array(
            'geocoded'        => $result,
            'nearest_objects' => $objects
        );
    }
```

In the example, we'll retrieve information from the user's IP address, and 5
objects nears him.
But it won't work on your local environment, that's why this bundle provides
an easy way to fake this behavior by using a `fake_ip` parameter.

``` yaml
# app/config/config_dev.yml
bazinga_geocoder:
    fake_ip:    123.345.643.133
```

If set, the parameter will replace the `REMOTE_ADDR` value by the given one.

## Dumpers ##

If you need to dump your geocoded data to a specific format, you can use the
__Dumper__ component. The following dumper's are supported:

 * Geojson
 * GPX
 * KMP
 * WKB
 * WKT

Here is an example:

```php
<?php

public function geocodeAction()
{
    $result = $this->container->get('bazinga_geocoder.geocoder')
        ->geocode($this->container->get('request')->server->get('REMOTE_ADDR'));

    $body = $this->container->get('bazinga_geocoder.dumper_manager')
        ->get('geojson')
        ->dump($result);

    $response = new Response();
    $response->setContent($body);

    return $response;
}
```

To register a new dumper, you must tag it with _geocoder.dumper_.
Geocoder detect and register it automaticly.

A little example:

```xml
<service id="some.dumper" class="%some.dumper.class">
    <tag name="geocoder.dumper" alias="custom" />
</service>
```


Reference Configuration
-----------------------

You have to define the providers you want to use in your configuration.
Some of them need information (API key for instance).

You'll find the reference configuration below:

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

bazinga_geocoder:
    fake_ip:    999.999.999.999
    adapter:
        class:  \Your\CustomAdapter
    providers:
        bing_maps:
            api_key:    <KEY>
            locale:     xx_XX
        google_maps:
            locale:     xx_XX
            region:     xx_XX
        ip_info_db:
            api_key:    <KEY>
        yahoo:
            api_key:    <KEY>
            locale:     xx_XX
        cloudmade:
            api_key:    <KEY>
        free_geo_ip: ~
        openstreetmaps:
            locale:     xx_XX
        host_ip: ~
        geoip: ~
        mapquest: ~
        oiorest: ~
        geocoder_ca: ~
        geocoder_us: ~
        ign_openls:
            api_key:    <KEY>
        data_science_toolkit: ~
        yandex:
            locale:     xx-XX
            toponym:    XXXXXXXXX
        geo_ips: ~
        geo_plugin: ~
        maxmind:
            api_key:    <KEY>
        # Caching Layer
        cache:
            provider: openstreetmaps
            cache: some_service_id
            lifetime: 86400
            locale: %locale%
```


Credits
-------
<commit_msg>[fix] Api_key for GeoIPs Provider isn't mentioned in readme.<commit_after>BazingaGeocoderBundle
=====================

[![Build
Status](https://secure.travis-ci.org/willdurand/BazingaGeocoderBundle.png)](http://travis-ci.org/willdurand/BazingaGeocoderBundle)

Integration of the [**Geocoder**](http://github.com/willdurand/Geocoder) library
into Symfony2.


Installation
------------

Using Composer, just add the following configuration to your `composer.json`:

```json
{
    "require": {
        "willdurand/geocoder-bundle": "*"
    }
}
```

Register the bundle in `app/AppKernel.php`:

    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new Bazinga\Bundle\GeocoderBundle\BazingaGeocoderBundle(),
        );
    }


Usage
-----

This bundle registers a `bazinga_geocoder.geocoder` service which is an instance
of `Geocoder`. You'll be able to do whatever you want with it.

#### Killer Feature ####

You can fake the `REMOTE_ADDR` HTTP parameter through this bundle in order to get
information in your development environment, for instance:

``` php
<?php

// ...

    /**
     * @Template()
     */
    public function indexAction()
    {
        // Retrieve information from the current user (by its IP address)
        $result = $this->geocoder
            ->using('yahoo')
            ->geocode($this->getRequest()->server->get('REMOTE_ADDR'));

        // Find the 5 nearest objects from the current user.
        $objects = ObjectQuery::create()
            ->filterByDistanceFrom($result->getLatitude(), $result->getLongitude(), 15)
            ->limit(5)
            ->find();

        return array(
            'geocoded'        => $result,
            'nearest_objects' => $objects
        );
    }
```

In the example, we'll retrieve information from the user's IP address, and 5
objects nears him.
But it won't work on your local environment, that's why this bundle provides
an easy way to fake this behavior by using a `fake_ip` parameter.

``` yaml
# app/config/config_dev.yml
bazinga_geocoder:
    fake_ip:    123.345.643.133
```

If set, the parameter will replace the `REMOTE_ADDR` value by the given one.

## Dumpers ##

If you need to dump your geocoded data to a specific format, you can use the
__Dumper__ component. The following dumper's are supported:

 * Geojson
 * GPX
 * KMP
 * WKB
 * WKT

Here is an example:

```php
<?php

public function geocodeAction()
{
    $result = $this->container->get('bazinga_geocoder.geocoder')
        ->geocode($this->container->get('request')->server->get('REMOTE_ADDR'));

    $body = $this->container->get('bazinga_geocoder.dumper_manager')
        ->get('geojson')
        ->dump($result);

    $response = new Response();
    $response->setContent($body);

    return $response;
}
```

To register a new dumper, you must tag it with _geocoder.dumper_.
Geocoder detect and register it automaticly.

A little example:

```xml
<service id="some.dumper" class="%some.dumper.class">
    <tag name="geocoder.dumper" alias="custom" />
</service>
```


Reference Configuration
-----------------------

You have to define the providers you want to use in your configuration.
Some of them need information (API key for instance).

You'll find the reference configuration below:

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

bazinga_geocoder:
    fake_ip:    999.999.999.999
    adapter:
        class:  \Your\CustomAdapter
    providers:
        bing_maps:
            api_key:    <KEY>
            locale:     xx_XX
        google_maps:
            locale:     xx_XX
            region:     xx_XX
        ip_info_db:
            api_key:    <KEY>
        yahoo:
            api_key:    <KEY>
            locale:     xx_XX
        cloudmade:
            api_key:    <KEY>
        free_geo_ip: ~
        openstreetmaps:
            locale:     xx_XX
        host_ip: ~
        geoip: ~
        mapquest: ~
        oiorest: ~
        geocoder_ca: ~
        geocoder_us: ~
        ign_openls:
            api_key:    <KEY>
        data_science_toolkit: ~
        yandex:
            locale:     xx-XX
            toponym:    XXXXXXXXX
        geo_ips: 
            api_key:    <KEY>
        geo_plugin: ~
        maxmind:
            api_key:    <KEY>
        # Caching Layer
        cache:
            provider: openstreetmaps
            cache: some_service_id
            lifetime: 86400
            locale: %locale%
```


Credits
-------

{'fraction_non_alphanumeric': 0.12400995700384702, 'fraction_numerical': 0.007920343969223807, 'mean_word_length': 2.2200364298724953, 'pattern_counts': {'":': 4, '<': 26, '<?xml version=': 0, '>': 72, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4342869', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2663, 'n_words': 728}