geocoder-php/geoip2-provider

Geocoder GeoIP2 适配器

4.3.0 2022-07-30 10:48 UTC

This package is auto-updated.

Last update: 2024-09-18 19:12:56 UTC


README

Build Status Latest Stable Version Total Downloads Monthly Downloads Quality Score Software License

这是 PHP Geocoder 的 GeoIP2 提供器。这是一个只读仓库。有关信息和文档,请参阅主仓库

安装

composer require geocoder-php/geoip2-provider

使用方法

此提供器需要数据库文件或付费访问网络服务。

使用数据库文件

支持免费 geolite2 和付费精度的 城市国家 数据库。

//Use a Maxmind GeoIP2 Database:
$reader = new \GeoIp2\Database\Reader('/path/to/geolite2.mmdb');

$adapter = new \Geocoder\Provider\GeoIP2\GeoIP2Adapter($reader);
$geocoder = new \Geocoder\Provider\GeoIP2\GeoIP2($adapter);

$address = $geocoder->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('74.200.247.59'))->first();

使用精确网络服务(API)

提供器还支持精确网络服务。请注意,这些 API 是付费的,按请求计费。

// Use the Maxmind GeoIP2 API:
$reader = new \GeoIp2\WebService\Client(<account_id>, '<licence_key>');

$adapter = new \Geocoder\Provider\GeoIP2\GeoIP2Adapter($reader);
$geocoder = new \Geocoder\Provider\GeoIP2\GeoIP2($adapter);

$address = $geocoder->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('74.200.247.59'))->first();

贡献

欢迎贡献!请向 主仓库 发送拉取请求,或在任何 问题跟踪器 上报告您发现的问题。