kubrey/geoservice 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kubrey/geoservice

Composer 安装命令:

composer require kubrey/geoservice

包简介

Geolocation module using multiple free geo services

README 文档

README

Searching geo data by IP address

Description

Include several services:

  • Maxmind
  • Ipgeobase.ru
  • Ipinfo.io
  • Freegeoip.net
  • Geobytes.com
  • Telize.com
  • Maxmind Legacy(v1)
  • IpApi(ip-api.com)

Installation

Composer.

Add kubrey/geoservice to your composer.json

OR

composer require kubrey/geoservice

If you have no composer, install beforehand:

Run in the project's root:

curl -s http://getcomposer.org/installer | php

And then :

php composer.phar init

Usage

require 'vendor/autoload.php';

use GeoServices\GeoService;
use GeoServices\GeoException;

$g = new GeoService();
try {
    //set maxmind v2  absolute path to mmdb file(if you want to use this method)
    $g->setMaxmindDb(dirname(__FILE__) . '/GeoLite2-City.mmdb');
    //set maxmind-legacy  absolute path to dat file(if you want to use this method)
    $g->setMaxmindOldDb(dirname(__FILE__).'/GeoLiteCity.dat');
    $data = $g->lookup('95.153.74.242');
    var_dump($data->city);
} catch (GeoException $ex) {
    echo $ex->getMessage();
}

$data is an instance of GeoObject, containing these properties:

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

To set your own method priority:

$g->maxmind = 1;//run first
$g->ipgeobaseru = false;//do not use
$g->ipinfo = 3;

To set required geo parameters

$g->isCityRequired = false; - поиск города не обязателен

To set timeout in milliseconds:

$g->setGlobalTimeout(5000);

To set timeout for each online service in milliseconds:

$g->setRequestTimeout(1000);

Tests

PHPUnit:

/usr/bin/php vendor/phpunit/phpunit/phpunit --colors --bootstrap vendor/autoload.php tests

统计信息

  • 总下载量: 3.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固