Location Services of FutureLink

2.1.4 2023-04-28 06:12 UTC

This package is auto-updated.

Last update: 2024-04-28 08:37:20 UTC


README

CircleCI codecov

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

Licensing

The code in this project is licensed under MIT license.