PHPackages                             pengyu/geo - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pengyu/geo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pengyu/geo
==========

a php geo library

01PHP

Since Aug 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/herepy/geo)[ Packagist](https://packagist.org/packages/pengyu/geo)[ RSS](/packages/pengyu-geo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

### 简介

[](#简介)

一个简单位置服务的库，多种驱动方式实现。

### 功能

[](#功能)

- 两地距离计算
- 查找附近的点

### 安装

[](#安装)

##### 必要条件

[](#必要条件)

目前可使用驱动有：redis(默认)、mongodb、elasticsearch,驱动可通过参数配置切换，使用某个驱动时，必须安装对应的软件，比如：redis &gt;= 3.2.0,mongodb &gt;= 2.4等

##### git方式

[](#git方式)

```
    git clone https://github.com/herepy/geo.git
    cd geo && composer install
```

##### composer方式

[](#composer方式)

```
    composer require pengyu/geo
```

##### 引入项目

[](#引入项目)

```
    use Pengyu\Geo\GeoClient;
    require "vendor/autoload.php";
```

### 示例

[](#示例)

##### 初始化实例

[](#初始化实例)

```
//使用mongodb驱动
$config=[
    "driver"    =>  "mongodb",
    "host"      =>  "localhost",
    "port"      =>  "27017",
];
//使用redis驱动
$config=[
    "driver"    =>  "redis",
    "host"      =>  "localhost",
    "port"      =>  "6379",
    "password"  =>  "12345"
];
$client=GeoClient::build($config);
```

##### 添加坐标点

[](#添加坐标点)

```
    //单个添加
    $client->add("chengdu",104.07,30.67);
    $client->add("deyang",104.38,31.13);
    $client->add("mianyang",104.67,31.46);
    //批量添加
    $client->bulk([
        ["name"=>"test1","lon"=>104.21,"lat"=>30.21],
        ["name"=>"test2","lon"=>105.12,"lat"=>31.69],
        ["name"=>"test3","lon"=>105.36,"lat"=>30.28],
    ]);
```

##### 删除

[](#删除)

```
    //删除单个坐标
    $client->del("chengdu");
    //清空所有坐标
    $client->flush();
```

##### 距离计算

[](#距离计算)

```
    //距离单位可选，默认为千米
    $client->distanceFrom("chengdu","mianyang",\Pengyu\Geo\Driver\DriverInterface::GEO_UNIT_KM)
```

##### 查找附近的点

[](#查找附近的点)

```
    //距离单位可选，默认为千米  返回格式：[["chengdu",0],["deyang",59.15161],["mianyang",104.9137]]
    $client->radiusFrom("chengdu",150000,\Pengyu\Geo\Driver\DriverInterface::GEO_UNIT_M);
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/49536efeca3900abb521efdeaa71377ce297b55a2fc8f91277ab87dbb0d72ec1?d=identicon)[Pengyu](/maintainers/Pengyu)

---

Top Contributors

[![herepy](https://avatars.githubusercontent.com/u/16030800?v=4)](https://github.com/herepy "herepy (36 commits)")

### Embed Badge

![Health badge](/badges/pengyu-geo/health.svg)

```
[![Health](https://phpackages.com/badges/pengyu-geo/health.svg)](https://phpackages.com/packages/pengyu-geo)
```

###  Alternatives

[spiral/mcp-server

Spiral bridge for MCP server

541.1k2](/packages/spiral-mcp-server)

PHPackages © 2026

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