Location Services of FutureLink
2.2.4
2024-09-20 02:40 UTC
Requires
- php: ^7.4
- ext-json: *
- ext-mbstring: *
- baohan/collection: ^1.0
- geoip2/geoip2: *
- guzzlehttp/guzzle: ~6.0
- monolog/monolog: ^1.3
Requires (Dev)
- phpunit/phpunit: ^9
README
ChinaFutureLink/GEO
提供地理服务相关接口。
Installing / Getting started
通过Composer安装
composer require fu/geo 2.*
将下面的代码加入composer.json
{ "require": { "fu/geo": "2.*" } }
Developing
Building
> vendor/bin/phpcs --standard=PSR12 src > vendor/bin/phpcbf --standard=PSR12 src > vendor/bin/phpunit Generating code coverage report in HTML format ... done [00:00.020]
Features
根据经纬度查询地理位置信息
include "./vendor/autoload.php"; use Fu\Geo\GeoCoder; use Fu\Geo\Service\Coordinary\TencentCoordinaryLocationService; const KEY = "YOUR-TENCENT-GEO-SERVICE-KEY"; $latitude = 29.60001; $longitude = 91.00001; $service = new TencentCoordinaryLocationService(KEY); $response = $service->getLocation($latitude, $longitude); if ($response->isOk()) { $area = $response->getArea(); $area->nation; // 中国 $area->lv1; // 西藏自治区 $area->lv2; // 拉萨市 $area->lv3; // 堆龙德庆区 } else { // get the response raw data... var_dump($response->getRaw()); }
根据IP地址查询地理位置信息
include "./vendor/autoload.php"; use Fu\Geo\IpCoder; use Fu\Geo\Service\Ip\TencentIpLocationService; const KEY = "YOUR-TENCENT-GEO-SERVICE-KEY"; $ip = '171.221.208.34'; $service = new TencentIpLocationService(KEY); $response = $service->getLocation($ip); if ($response->isOk()) { $area = $response->getArea() $area->nation; // 中国 $area->lv1; // 四川省 $area->lv2; // 成都市 $area->lv3; // 温江区 } else { // get the response raw data... var_dump($response->getRaw()); }
根据手机号码查询地理位置信息
include "./vendor/autoload.php"; use Fu\Geo\IpCoder; use Fu\Geo\Service\Phone\AliPhoneLocationService; const KEY = "YOUR-ALI-SERVICE-KEY"; $areaCode = '86'; $phone = '13880799123'; $service = new AliPhoneLocationService(KEY); $response = $service->getLocation($areaCode, $phone); if ($response->isOk()) { $area = $response->getArea() $area->nation; // 中国 $area->lv1; // 四川省 $area->lv2; // 成都市 $area->lv3; // 温江区 } else { // get the response raw data... var_dump($response->getRaw()); }
Links
- 腾讯地理位置服务:https://lbs.qq.com
- 阿里云市场手机归属地查询服务
Licensing
The code in this project is licensed under MIT license.