zero-config/geo-distance
Composer 安装命令:
composer require zero-config/geo-distance
包简介
Calculate the distance between coordinates.
README 文档
README
Calculate the distance between coordinates.
This package uses the UnitAngle and UnitLength classes from
nmarfurt/measurements.
Further, resulting measurements, like distance, are represented by a Measurement.
To make full use of this library, it is recommended to familiarize oneself with
that package first.
Installation
composer require zero-config/geo-distance
Procedural approach
To use the data models for coordinates and distance calculation in a procedural manner, try the following:
<?php use function ZeroConfig\GeoDistance\coordinates; use function ZeroConfig\GeoDistance\distance; // Returns a distance of approximately 361 kilometers. // The distance function uses the distance calculator under the hood. // It assumes earth as base sphere for calculations. echo distance( coordinates(50.0, 5.0), coordinates(53.0, 3.0) ) . PHP_EOL;
coordinates
The coordinates function accepts:
float $latitudefloat $longitude
Both are a number representing an angle in degrees.
It returns an instance of:
ZeroConfig\GeoDistance\PositionInterface
<?php use function ZeroConfig\GeoDistance\coordinates; // This outputs: 50.6 ° echo coordinates(50.6, 5.0)->getLatitude() . PHP_EOL;
distance
The distance function accepts:
ZeroConfig\GeoDistance\PositionInterface $startZeroConfig\GeoDistance\PositionInterface $end
Both are positions on a sphere.
It returns an instance of:
Measurements\Measurement
<?php use function ZeroConfig\GeoDistance\coordinates; use function ZeroConfig\GeoDistance\distance; use Measurements\Units\UnitLength; // Outputs: 36113.471850273 dam echo distance( coordinates(50.0, 5.0), coordinates(53.0, 3.0) )->convertTo(UnitLength::decameters()) . PHP_EOL;
Object oriented approach
The following data models exist:
- Position, combined latitude and longitude
- Sphere, the object on which coordinates are plotted when calculating distance
<?php use ZeroConfig\GeoDistance\ConvertedDistanceCalculator; use ZeroConfig\GeoDistance\DistanceCalculator; use ZeroConfig\GeoDistance\Position; use ZeroConfig\GeoDistance\Sphere\CelestialBody\Mars; use Measurements\Units\UnitLength; $marsDistanceCalculator = new ConvertedDistanceCalculator( new DistanceCalculator(new Mars()), UnitLength::kilometers() ); // On Mars, the same coordinates as on earth, give a distance of only 192 kilometers. echo $marsDistanceCalculator->calculate( Position::create(50.0, 5.0), Position::create(53.0, 3.0) ) . PHP_EOL;
zero-config/geo-distance 适用场景与选型建议
zero-config/geo-distance 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geo」 「distance」 「latitude」 「longitude」 「earth」 「mars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zero-config/geo-distance 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zero-config/geo-distance 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zero-config/geo-distance 相关的其它包
同方向 / 同关键字的高下载量 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
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
Add a weather widget to Flarum
Simple class for basic google maps distance calculations.
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2017-05-25