jeroendesloovere / distance
使用PHP获取两个位置之间的距离。
1.0.2.1
2015-05-20 15:13 UTC
Requires
- php: >=5.3.3
This package is auto-updated.
Last update: 2024-09-08 08:35:46 UTC
README
使用PHP获取两个位置之间的距离。距离是基于纬度和经度变量计算得出的,且不使用任何其他外部类。
用法
使用Composer安装
当使用 Composer 时,您可以始终加载最新版本。
{ "require": { "jeroendesloovere/distance": "1.0.*" } }
在 Packagist 上检查。
示例
设置示例数据
use JeroenDesloovere\Distance\Distance; // first location $latitude1 = '50.8538510000'; $longitude1 = '3.3550450000'; // second location $latitude2 = '50.8325600000'; $longitude2 = '3.4787650000';
获取两个位置之间的距离
$distance = Distance::between( $latitude1, $longitude1, $latitude2, $longitude2 ); // dump data echo 'Distance between the two locations = ' . $distance . ' km';
获取位置1到两个位置(2和3)中任意一个的最短距离
// third location $latitude3 = '50.8865040000'; $longitude3 = '3.4320850000'; // define multiple items $items = array( array( 'title' => 'location 2', 'latitude' => $latitude2, 'longitude' => $longitude2 ), array( 'title' => 'location 3', 'latitude' => $latitude3, 'longitude' => $longitude3 ) ); $distance = Distance::getClosest( $latitude1, $longitude1, $items ); // dump data echo 'The closest location to location 1 is ' . $distance['title'] . ' and the distance between them is ' . $distance['distance'] . ' km';
文档
类有良好的内联文档。如果您使用的是良好的IDE,您会看到每个方法都用PHPDoc进行了文档说明。
贡献
如果您能帮助我们改进这个类,那将非常棒。GitHub通过提供不同的工具在管理协作方面做得很好,您唯一需要的是GitHub 登录。
- 使用 拉取请求 来添加或更新代码
- 问题 用于错误报告或代码讨论
- 有关文档和如何做的更多信息,请查看 Wiki。有关如何在help.github.com上与GitHub合作更多信息。
许可证
本模块受MIT许可证的约束。简而言之,此许可证允许您做任何事,只要版权声明仍然存在。