sivolobov/geocoder-ipgeobase

IpGeoBase服务(俄罗斯)的Geocoder提供者。

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

This package is auto-updated.

Last update: 2024-09-16 21:02:04 UTC


README

SensioLabsInsight

此存储库托管IpGeoBase提供者,用于与Geocoder库一起使用。

安装

安装此软件包的推荐方式是通过Composer

composer require sivolobov/geocoder-ipgeobase

用法

您需要先阅读Geocoder的使用文档

简单示例

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

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

Symfony集成

要在Symfony项目中使用IpGeoBase,您需要安装BazingaGeocoderBundle

配置完bundle后,您需要定义自定义提供者。因此,将这些行添加到您的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

现在您可以使用它

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

注意

请注意,geocode()返回AddressCollection实例,但IpGeoBase总是为每个IP地址返回一个地址。因此,该集合将始终只有一个元素。

许可证

Geocoder IpGeoBase提供者是根据MIT许可证发布的。有关详细信息,请参阅捆绑的LICENSE文件。