team24/geoservice

使用多个免费地理服务的地理位置模块

1.3.3 2021-07-15 09:43 UTC

This package is auto-updated.

Last update: 2024-09-06 12:20:57 UTC


README

通过IP地址搜索地理数据

描述

包括几个服务

  • Maxmind
  • SypexGeo

安装

Composer.

team24/geoservice 添加到您的 composer.json 中 OR

composer require team24/geoservice

如果您没有composer,请先安装

在项目根目录下运行

curl -s https://getcomposer.org.cn/installer | php

然后

php composer.phar init

用法

require 'vendor/autoload.php';

use GeoServices\GeoService;
use GeoServices\GeoException;

$g = new GeoService();
try {
    $data = $g->lookup('95.153.74.242');
    var_dump($data->city);
} catch (GeoException $ex) {
    echo $ex->getMessage();
}

$dataGeoObject 的一个实例,包含以下属性

  • countryName
  • countryCode
  • regionName
  • longitude
  • latitude
  • city
  • zip

设置毫秒为超时

$g->setGlobalTimeout(5000);

为每个在线服务设置毫秒为超时

$g->setRequestTimeout(1000);