PHPackages                             lanxr/ip-locating - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lanxr/ip-locating

ActiveLibrary

lanxr/ip-locating
=================

Amap ip locating SDK.

0.0.1(5y ago)23MITPHP

Since Sep 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/lanxr/ip-locating)[ Packagist](https://packagist.org/packages/lanxr/ip-locating)[ RSS](/packages/lanxr-ip-locating/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

IP-Locating
===========

[](#ip-locating)

基于高德开放平台的 PHP IP 定位组件。

安装
--

[](#安装)

```
$ composer require lanxr/ip-locating -vvv
```

配置
--

[](#配置)

在使用本扩展之前，你需要去 [高德开放平台](https://lbs.amap.com/dev/id/newuser) 注册账号，然后创建应用，获取应用的 API Key。

使用
--

[](#使用)

```
use Lanxr\Locating\IPLocating;

$key = 'xxxxxxxxxx';

$ipLocating = new IPLocating($key);
```

### 获取 IP 定位信息

[](#获取-ip-定位信息)

```
$response = $ipLocating->getIPLocating('114.247.50.2');
```

返回示例：

```
{
    "status": "1",
    "info": "OK",
    "infocode": "10000",
    "province": "北京市",
    "city": "北京市",
    "adcode": "110000",
    "rectangle": "116.0119343,39.66127144;116.7829835,40.2164962"
}
```

### 获取 XML 格式返回值

[](#获取-xml-格式返回值)

第二个参数为返回值类型，可选 `json` 与 `xml` ，默认 `json` ：

```
$response = $ipLocating->getIPLocating('114.247.50.2', 'xml');
```

```

    1
    OK
    10000
    北京市
    北京市
    110000
    116.0119343,39.66127144;116.7829835,40.2164962

```

### 参数说明

[](#参数说明)

```
array | string getIPLocating(string $ip, string $format = 'json')

```

> - `$ip` - IP 字符串，例如（'114.247.50.2'）
> - `$format` - 输出数据格式，默认为 `json` 格式，当设置为 `xml` 时，输出为 XML 格式的数据

### 在 Laravel 中使用

[](#在-laravel-中使用)

在 Laravel 中使用也是同样的安装方式，配置写在 `config/services.php` 中：

```
    .
    .
    .
    'locating' => [
        'key' => env('IP_LOCATING_API_KEY'),
    ],
    .
    .
    .
```

然后在 `.env` 中配置 `IP_LOCATING_API_KEY` ：

```
IP_LOCATING_API_KEY=xxxxxxxxxxx
```

可以用两种方法来获取 `Lanxr\Locating\IPLocating` 实例：

#### 方法参数注入

[](#方法参数注入)

```
    .
    .
    .
    public function show(IPLocating $ipLocating)
    {
        $response = $ipLocating->getIPLocating('114.247.50.2');
    }
    .
    .
    .
```

#### 服务名访问

[](#服务名访问)

```
    .
    .
    .
    public function show()
    {
        $response = app('ipLocating')->getIPLocating('114.247.50.2');
    }
    .
    .
    .
```

参考
--

[](#参考)

- [高德开放平台 IP 定位接口](https://lbs.amap.com/api/webservice/guide/api/ipconfig)

License
-------

[](#license)

MIT

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2074d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5842375e41723bfe3c3b0b187987f85fdfb7f1a53701523250ac15320b5bf611?d=identicon)[lanxr](/maintainers/lanxr)

---

Top Contributors

[![lanxr](https://avatars.githubusercontent.com/u/21061548?v=4)](https://github.com/lanxr "lanxr (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lanxr-ip-locating/health.svg)

```
[![Health](https://phpackages.com/badges/lanxr-ip-locating/health.svg)](https://phpackages.com/packages/lanxr-ip-locating)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k20](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
