matthiasmullie/geo
Composer 安装命令:
composer require matthiasmullie/geo
包简介
Geography helper
README 文档
README
I strongly suggest reading some background information at https://www.mullie.eu/geographic-searches/
Usage
Find anything in a 10km radius of Kortrijk railway station
The Geo class is particularly useful to do simple distance-based calculations:
$geo = new Geo\Geo('km'); // coord of Kortrijk railway station $coord = new Geo\Coordinate(50.824167, 3.263889); // calculate bounding box of 10km around this coordinate $bounds = $geo->bounds($coord, 10); /* * Now pass this on this the database, so it executes a query like: * SELECT * * FROM coordinates * WHERE * lat BETWEEN :swlat AND :nelat * lng BETWEEN :swlng AND :nelng * * :swlat being $bounds->sw->latitude * :swlng being $bounds->sw->longitude * :nelat being $bounds->ne->latitude * :nelng being $bounds->ne->longitude * * Assume we have the database results in a variable called $results */ // now weed out entries that fit in the bounding box, but not exactly in // the radius we want them to be in foreach ($results as $i => $result) { $resultCoord = new Geo\Coordinate($result['lat'], $result['lng']); // actual distance between source coordinate & result from DB $distance = $geo->distance($coord, $resultCoord); // if distance is too large, get rid of the result if ($distance > 10) { unset($results[$i]); } }
Cluster coordinates
The Clusterer class can be useful when dealing with a huge amount of locations.
E.g. you want to display thousands of locations on a map. Google Maps (and
probably others too) can create clusters too, but you'll still have to get all
locations to your frontend. Instead of outputting all coordinates and waiting
for the full list to load, we can do the clustering in PHP already & serve that
frontend of yours a more lightweight selection of coordinates!
$clusterer = new Geo\Clusterer( // your viewport: in this case an approximation of bounding box around Belgium new Geo\Bounds( new Geo\Coordinate(51.474654, 6.344604), new Geo\Coordinate(49.482639, 2.471924) ) ); // create a matrix of about 12 cells (this may differ from 12, depending on // the exact measurements of the bounding box) $clusterer->setNumberOfClusters(12); // start clustering after 2 locations in the same cell $clusterer->setMinClusterLocations(2); // add locations to clusterer $clusterer->addCoordinate(new Geo\Coordinate(50.824167, 3.263889)); // Kortrijk railway station $clusterer->addCoordinate(new Geo\Coordinate(51.035278, 3.709722)); // Gent-Sint-Pieters railway station $clusterer->addCoordinate(new Geo\Coordinate(50.881365, 4.715682)); // Leuven railway station $clusterer->addCoordinate(new Geo\Coordinate(50.860526, 4.361787)); // Brussels North railway station $clusterer->addCoordinate(new Geo\Coordinate(50.836712, 4.337521)); // Brussels South railway station $clusterer->addCoordinate(new Geo\Coordinate(50.845466, 4.357113)); // Brussels Central railway station $clusterer->addCoordinate(new Geo\Coordinate(51.216227, 4.421180)); // Antwerpen Central railway station // now get the results... $clusterer->getClusters(); // returns 1 cluster: all 3 Brussels stations $clusterer->getCoordinates(); // returns 4 non-clustered coordinates
Installation
Simply add a dependency on matthiasmullie/geo to your composer.json file if you use Composer to manage the dependencies of your project:
composer require matthiasmullie/geo
Although it's recommended to use Composer, you can actually include these files anyway you want.
License
Geo is MIT licensed.
matthiasmullie/geo 适用场景与选型建议
matthiasmullie/geo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 80.43k 次下载、GitHub Stars 达 63, 最近一次更新时间为 2014 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geo」 「distance」 「geography」 「coordinate」 「cluster」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 matthiasmullie/geo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 matthiasmullie/geo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 matthiasmullie/geo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Get distance between two locations using PHP.
Show geo marker on a mapbox map
Show geo shape on a mapbox map with drawing capabilities
PHP FFI bindings for Uber's H3 hexagonal hierarchical geospatial indexing system
Geo-Toolkit for PHP
Add a weather widget to Flarum
统计信息
- 总下载量: 80.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 63
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-30