ixnode/php-coordinate 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ixnode/php-coordinate

Composer 安装命令:

composer require ixnode/php-coordinate

包简介

PHP Coordinate - This library offers a collection of various PHP coordinate classes like Coordinate, etc.

README 文档

README

Release PHP PHPStan PHPUnit PHPCS PHPMD Rector - Instant Upgrades and Automated Refactoring LICENSE

This library offers a collection of various PHP coordinate classes like Coordinate, etc. It converts various coordinate strings and values into a unique format.

1. Usage

use Ixnode\PhpCoordinate\Coordinate;

1.1 Converter example

$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 Parser example

$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 Distance example

$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 Direction example (degree)

$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 Direction example (cardinal direction)

$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. Parser

2.1 Basic decimal degree parser

2.1.1 Parser formats

Given value (string) Latitude (float) Longitude (float) Place
"51.0504,13.7373" 51.0504 13.7373 Dresden, Germany
"51.0504, 13.7373" 51.0504 13.7373 Dresden, Germany
"51.0504 13.7373" 51.0504 13.7373 Dresden, Germany
"POINT(-31.425299, -64.201743)" -31.425299 -64.201743 Córdoba, Argentina
"POINT(-31.425299 -64.201743)" -31.425299 -64.201743 Córdoba, Argentina

2.1.2 Code example

$coordinate = new Coordinate('51.0504 13.7373');

print $coordinate->getLatitude();
// (float) 51.0504

print $coordinate->getLongitude();
// (float) 13.7373

2.2 Basic DMS Parser

2.2.1 Parser formats

Given value (string) Latitude (float) Longitude (float) Place
"51°3′1.44″N,13°44′14.28″E" 51.0504 13.7373 Dresden, Germany
"51°3′1.44″N, 13°44′14.28″E" 51.0504 13.7373 Dresden, Germany
"51°3′1.44″N 13°44′14.28″E" 51.0504 13.7373 Dresden, Germany
"POINT(31°25′31.0764″S, 64°12′6.2748″W)" -31.425299 -64.201743 Córdoba, Argentina
"POINT(31°25′31.0764″S 64°12′6.2748″W)" -31.425299 -64.201743 Córdoba, Argentina

2.2.2 Code example

$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 Parser Parser

2.3.1 Parser formats

Given value (string) Latitude (float) Longitude (float) Place
Copied Google Maps Short Url1) 54.07304830 18.992402 Malbork, Poland
Copied Google Maps Link2) 51.31237 12.4132924 Leipzig, Germany

2.3.2 Code example

$coordinate = new Coordinate('https://maps.app.goo.gl/PHq5axBaDdgRWj4T6');

print $coordinate->getLatitude();
// (float) 54.07304830

print $coordinate->getLongitude();
// (float) 18.992402

3. Converter

3.1 Methods of class Coordinate

Method Type Parameter(s) Description Example
getLatitude float --- Returns the decimal degree presentation of latitude value. -31.425299
getLongitude float --- Returns the decimal degree presentation of longitude value. -64.201743
getLatitudeDD float --- Alias of getLatitude. -31.425299
getLongitudeDD float --- Alias of getLongitude. -64.201743
getLatitudeDMS string --- Returns the dms representation of the latitude value. "31°25′31.0764″S"
getLongitudeDMS string --- Returns the dms representation of the longitude value. "64°12′6.2748″W"
getLatitudeDMS string CoordinateValue::FORMAT_DMS_SHORT_2 Returns the dms representation of the latitude value (v2). "S31°25′31.0764″"
getLongitudeDMS string CoordinateValue::FORMAT_DMS_SHORT_2 Returns the dms representation of the longitude value (v2). "W64°12′6.2748″"
getDistance float new Coordinate(), meters (default) or kilometers Returns the distance to given second Coordinate instance. 11904.668
getDegree float new Coordinate() Returns the direction (degree) to given second Coordinate instance (0° - North, 90° - East, etc.). -136.62
getDirection string new Coordinate() Returns the cardinal direction to given second Coordinate instance (N, NE, E, SE, S, SW, W, NW). "SW"
getLinkGoogle string false (default - as decimal) or true (as DMS) Returns the link to Google. Google
getLinkOpenStreetMap string --- Returns the link to OpenStreetMap. OpenStreetMap

3.2 Code example

$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. Installation

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. Command line tool

Used to quickly check two given coordinates.

Check Dresden, Germany and New York, United States:

bin/console pc "51°3′1.44″N, 13°44′14.28″E" "40.712784, -74.005941"

or within your composer project:

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                          |
||   |                                       |
|                                    |   |       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°) |
+------------------------------------+   +---------------------------------------+

Services

6. Library development

git clone git@github.com:ixnode/php-coordinate.git && cd php-coordinate
composer install
composer test

7. License

This library is licensed under the MIT License - see the LICENSE file for details.

ixnode/php-coordinate 适用场景与选型建议

ixnode/php-coordinate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.19k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「parser」 「conversion」 「coordinate」 「latitude」 「longitude」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ixnode/php-coordinate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ixnode/php-coordinate 我们能提供哪些服务?
定制开发 / 二次开发

基于 ixnode/php-coordinate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 19
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-03