sivolobov/geocoder-ipgeobase

Geocoder provider for IpGeoBase service (Russia).

v1.0.3 2017-12-12 07:36 UTC

This package is auto-updated.

Last update: 2024-10-16 21:12:28 UTC


README

SensioLabsInsight

This repository hosts IpGeoBase provider to use with Geocoder library.

Installation

The recommended way to install this package is through Composer:

composer require sivolobov/geocoder-ipgeobase

Usage

You need to read Geocoder's usage documentaion first.

Simple example:

$curl     = new \Ivory\HttpAdapter\CurlHttpAdapter();
$geocoder = new \Geocoder\Provider\IpGeoBase($curl);

$addressCollection = $geocoder->geocode('213.180.193.3');

Symfony integration

To use IpGeoBase in Symfony project you need to install BazingaGeocoderBundle:

After configuring bundle you need to define custom provider. So add these lines to your services.yml:

bazinga_geocoder.provider.ip_geo_base:
    class:  Geocoder\Provider\IpGeoBase
    arguments:
        - "@bazinga_geocoder.geocoder.adapter"
    tags:
        - {name: "bazinga_geocoder.provider"}
    public: false
    lazy:   true

Now you can use it as:

$addressCollection = $this->get('geocoder')->using('ip_geo_base')->geocode($request->getClientIp());

Notes

Note that geocode() return AddressCollection instance but IpGeoBase always return only one address for one IP. So that collection will always have only one element.

License

Geocoder IpGeoBase provider is released under the MIT License. See the bundled LICENSE file for details.