Geocoder IpGeoBase provider
, (*1)
This repository hosts IpGeoBase provider to use with Geocoder library., (*2)
Installation
The recommended way to install this package is through Composer:, (*3)
composer require sivolobov/geocoder-ipgeobase
Usage
You need to read Geocoder's usage documentaion first., (*4)
Simple example:, (*5)
$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][2]:, (*6)
After configuring bundle you need to define custom provider. So add these lines to your services.yml:, (*7)
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:, (*8)
$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., (*9)
License
Geocoder IpGeoBase provider is released under the MIT License. See the bundled LICENSE file
for details., (*10)