ballen/distical

一个用于PHP的距离(经纬度)计算库

3.1.0 2023-11-08 13:47 UTC

This package is auto-updated.

Last update: 2024-09-08 15:56:36 UTC


README

Build Code Coverage Scrutinizer Code Quality Code Climate Latest Stable Version Latest Unstable Version License

Distical是一个PHP距离计算库,主要用于计算两个或多个经纬度坐标之间的距离。

许可证

此客户端库遵循MIT许可证发布。

要求

此库已针对PHP 7.3、7.4、8.0、8.1和8.2进行了单元测试!

如果您需要使用较旧的PHP版本,应安装此库的3.x版本(以下为详细信息)。

设置

强烈建议在安装和使用此库时使用Composer,但这不是强制性的。如果需要,您可以使用提供的'include'脚本来加载此库。

Composer

只需按以下方式要求此包

composer require ballen/distical

如果您需要使用较旧的PHP版本,2.x.x版本支持PHP 5.3、5.4、5.5、5.6、7.0、7.1和7.2,您可以使用Composer使用以下命令安装此版本

composer require ballen/disitcal ^2.0
composer install

独立使用

您可以通过从GitHub发行版部分下载库,将文件提取到您的服务器上的某个位置,然后在您的代码中添加"include"来独立使用此库

require_once 'path/to/Distical/Distical.inc.php';

示例

use Ballen\Distical\Calculator as DistanceCalculator;
use Ballen\Distical\Entities\LatLong;

// Set our Lat/Long coordinates
$ipswich = new LatLong(52.057941, 1.147172);
$london = new LatLong(51.507608, -0.127822);

// Get the distance between these two Lat/Long coordinates...
$distanceCalculator = new DistanceCalculator($ipswich, $london);

// You can then compute the distance...
$distance = $distanceCalculator->get();
// you can also chain these methods together eg. $distanceCalculator->get()->asMiles();

// We can now output the miles using the asMiles() method, you can also calculate and use asKilometres() or asNauticalMiles() as required!
echo 'Distance in miles between Central Ipswich and Central London is: ' . $distance->asMiles();

包括多点计算在内的一组工作示例可以在/examples目录中找到,您可以自由浏览或运行它们!

测试和覆盖率

此库完全使用PHPUnit进行单元测试。

我使用GitHub Actions进行持续集成,每次提交都会触发PHP 7.3、7.4、8.0、8.1和8.2的测试。

如果您想自己运行测试,应运行以下命令

# Install the Distical Library with the 'development' packages this then including PHPUnit!
composer install

# Now we run the unit tests (from the root of the project) like so:
./vendor/bin/phpunit

还可以运行代码覆盖率测试,但需要安装XDebug...

./vendor/bin/phpunit --coverage-html ./report

支持

我很乐意通过我的个人电子邮件地址提供支持,因此如果您需要帮助,请将电子邮件发送到: ballen@bobbyallen.me