ixnode / php-coordinate
PHP 坐标 - 这个库提供了一系列 PHP 坐标类,如 Coordinate 等。
0.1.21
2024-04-08 14:24 UTC
Requires
- php: ^8.2
- ext-curl: *
- ext-gd: *
- adhocore/cli: ^v1.0.0
- ixnode/php-cli-image: ^0.1.1
- ixnode/php-exception: ^0.1.21
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- ixnode/bash-version-manager: ^0.1.3
- jetbrains/phpstorm-attributes: ^1.0
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- povils/phpmnd: ^3.0
- rector/rector: ^0.15.1
README
这个库提供了一系列 PHP 坐标类,如 Coordinate 等。它可以将各种坐标字符串和值转换为唯一格式。
1. 使用方法
use Ixnode\PhpCoordinate\Coordinate;
1.1 转换器示例
$coordinate = new Coordinate(51.0504, 13.7373); print $coordinate->getLatitudeDMS(); // (string) 51°3′1.44″N print $coordinate->getLongitudeDMS(); // (string) 13°44′14.28″E
1.2 解析器示例
$coordinate = new Coordinate('51°3′1.44″N 13°44′14.28″E'); print $coordinate->getLatitude(); // (float) 51.0504 print $coordinate->getLongitude(); // (float) 13.7373
1.3 距离示例
$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E'); $coordinateCordoba = new Coordinate(-31.425299, -64.201743); /* Distance between Dresden, Germany and Córdoba, Argentina */ print $coordinate->getDistance($coordinateCordoba, Coordinate::RETURN_KILOMETERS); // (float) 11904.668
1.4 方向示例(度数)
$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E'); $coordinateCordoba = new Coordinate(-31.425299, -64.201743); /* Direction in degrees from Dresden, Germany to Córdoba, Argentina */ print $coordinateDresden->getDegree($coordinateCordoba); // (float) -136.62°
1.5 方向示例(方位方向)
$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E'); $coordinateCordoba = new Coordinate(-31.425299, -64.201743); /* Direction in degrees from Dresden, Germany to Córdoba, Argentina */ print $coordinateDresden->getDirection($coordinateCordoba); // (string) SW
2. 解析器
2.1 基本十进制度数解析器
2.1.1 解析器格式
2.1.2 代码示例
$coordinate = new Coordinate('51.0504 13.7373'); print $coordinate->getLatitude(); // (float) 51.0504 print $coordinate->getLongitude(); // (float) 13.7373
2.2 基本DMS解析器
2.2.1 解析器格式
2.2.2 代码示例
$coordinate = new Coordinate('51°3′1.44″N 13°44′14.28″E'); print $coordinate->getLatitude(); // (float) 51.0504 print $coordinate->getLongitude(); // (float) 13.7373
2.3 Google URL 解析器
2.3.1 解析器格式
2.3.2 代码示例
$coordinate = new Coordinate('https://maps.app.goo.gl/PHq5axBaDdgRWj4T6'); print $coordinate->getLatitude(); // (float) 54.07304830 print $coordinate->getLongitude(); // (float) 18.992402
3. 转换器
3.1 Coordinate
类的方法
3.2 代码示例
$coordinate = new Coordinate('-31.425299, -64.201743'); print $coordinate->getLatitudeDMS(); // (string) "31°25′31.0764″S" print $coordinate->getLongitudeDMS(); // (string) "64°12′6.2748″W"
4. 安装
composer require ixnode/php-coordinate
vendor/bin/php-coordinate -V
php-coordinate 0.1.0 (03-07-2023 01:17:26) - Björn Hempel <bjoern@hempel.li>
5. 命令行工具
用于快速检查两个给定坐标。
检查 德累斯顿,德国 和 纽约,美国
bin/console pc "51°3′1.44″N, 13°44′14.28″E" "40.712784, -74.005941"
或在您的 composer 项目中
vendor/bin/php-coordinate pc "51°3′1.44″N, 13°44′14.28″E" "40.712784, -74.005941"
Source coordinate (51°3′1.44″N, 13°44′14.28″E): +---------+------------------+--------------------+ | Value | Latitude | Longitude | +---------+------------------+--------------------+ | Decimal | 51.0504 | 13.7373 | | DMS | 51°3′1.44″N | 13°44′14.28″E | +---------+------------------+--------------------+ Target coordinate (40.712784, -74.005941): +---------+----------------------+---------------------+ | Value | Latitude | Longitude | +---------+----------------------+---------------------+ | Decimal | 40.712784 | -74.005941 | | DMS | 40°42′46.0224″N | 74°0′21.3876″W | +---------+----------------------+---------------------+ Distance: +-----------+-------------+ | Key | Value | +-----------+-------------+ | Distance | 6478.472 km | | Degree | -96.720° | | Direction | W | +-----------+-------------+ +--------------------------------------------------------------------------------+ | World map | +--------------------------------------------------------------------------------+ | | | ▄▄▄▄▀▄▄▄▄▄▄▄▄▄▄ | | ▄▄ ▄▄▄▄▄▄▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄▄▄▄▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄ | | ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄ ▀▀ | | ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄ | | ▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀▄▄ ▀ ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▄▄▀▀▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀▀▀ | | ▀▀▀▀▀▀▀▀▀▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▄ ▄▀▀ | | ▀▀▀▀▀▀▀▀▀▀▀▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▄▄▄▄ | | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▄| | ▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▄▀▀ ▄▀▀▀▀▀▀ | | ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀▀ ▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ | | ▀▀▀▀ ▀ | | ▀▀▀ | +--------------------------------------------------------------------------------+ +------------------------------------+ +---------------------------------------+ | Cardinal direction | | Longitude / Langitude | +------------------------------------| +---------------------------------------| | | | lat | | 0° | | | | | | 90° ⯅ | | ___ | | | | | -45° ─── 45° | | | | | // N \\ | | | • Oslo (59.91°, 10.75°) | | NW NE | | | • London (51.51°, -0.13°) | | | | | • New York (40.71°, -74.01°) | | -90° || W --+-- E || 90° | | | | | | | | | | | SW SE | | | | | \\ S // | | | • Null Island (0°, 0°) | | -135° ─── 135° | | ⯇-------+-------------------⯈ lon | | ‾‾‾ | | -180° | 180° | | | | | | | 180° | | | • Cape Agulhas | | | | -90° ⯆ (-34.82°, 20.02°) | +------------------------------------+ +---------------------------------------+
6. 库开发
git clone git@github.com:ixnode/php-coordinate.git && cd php-coordinate
composer install
composer test
7. 许可证
此库采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。