{"id":18610574,"url":"https://github.com/ixnode/php-coordinate","last_synced_at":"2025-04-10T22:32:20.098Z","repository":{"id":178414032,"uuid":"661831882","full_name":"ixnode/php-coordinate","owner":"ixnode","description":"This library offers a collection of various PHP coordinate classes like Coordinate, etc. It converts various coordinate strings and values into a unique format.","archived":false,"fork":false,"pushed_at":"2024-12-07T11:56:11.000Z","size":222,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T05:51:14.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ixnode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-03T18:52:35.000Z","updated_at":"2024-12-07T11:56:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"67ed9796-88a6-4c6e-a3f5-2aa01bf21011","html_url":"https://github.com/ixnode/php-coordinate","commit_stats":null,"previous_names":["ixnode/php-coordinate"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-coordinate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-coordinate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-coordinate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-coordinate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ixnode","download_url":"https://codeload.github.com/ixnode/php-coordinate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248310105,"owners_count":21082348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T03:11:06.867Z","updated_at":"2025-04-10T22:32:15.213Z","avatar_url":"https://github.com/ixnode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Coordinate\n\n[![Release](https://img.shields.io/github/v/release/ixnode/php-coordinate)](https://github.com/ixnode/php-coordinate/releases)\n[![](https://img.shields.io/github/release-date/ixnode/php-coordinate)](https://github.com/ixnode/php-coordinate/releases)\n![](https://img.shields.io/github/repo-size/ixnode/php-coordinate.svg)\n[![PHP](https://img.shields.io/badge/PHP-^8.2-777bb3.svg?logo=php\u0026logoColor=white\u0026labelColor=555555\u0026style=flat)](https://www.php.net/supported-versions.php)\n[![PHPStan](https://img.shields.io/badge/PHPStan-Level%20Max-777bb3.svg?style=flat)](https://phpstan.org/user-guide/rule-levels)\n[![PHPUnit](https://img.shields.io/badge/PHPUnit-Unit%20Tests-6b9bd2.svg?style=flat)](https://phpunit.de)\n[![PHPCS](https://img.shields.io/badge/PHPCS-PSR12-416d4e.svg?style=flat)](https://www.php-fig.org/psr/psr-12/)\n[![PHPMD](https://img.shields.io/badge/PHPMD-ALL-364a83.svg?style=flat)](https://github.com/phpmd/phpmd)\n[![Rector - Instant Upgrades and Automated Refactoring](https://img.shields.io/badge/Rector-PHP%208.2-73a165.svg?style=flat)](https://github.com/rectorphp/rector)\n[![LICENSE](https://img.shields.io/github/license/ixnode/php-api-version-bundle)](https://github.com/ixnode/php-api-version-bundle/blob/master/LICENSE)\n\n\u003e This library offers a collection of various PHP coordinate classes like Coordinate, etc.\n\u003e It converts various coordinate strings and values into a unique format.\n\n## 1. Usage\n\n```php\nuse Ixnode\\PhpCoordinate\\Coordinate;\n```\n\n### 1.1 Converter example\n\n```php\n$coordinate = new Coordinate(51.0504, 13.7373);\n\nprint $coordinate-\u003egetLatitudeDMS();\n// (string) 51°3′1.44″N\n\nprint $coordinate-\u003egetLongitudeDMS();\n// (string) 13°44′14.28″E\n```\n\n### 1.2 Parser example\n\n```php\n$coordinate = new Coordinate('51°3′1.44″N 13°44′14.28″E');\n\nprint $coordinate-\u003egetLatitude();\n// (float) 51.0504\n\nprint $coordinate-\u003egetLongitude();\n// (float) 13.7373\n```\n\n### 1.3 Distance example\n\n```php\n$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E');\n$coordinateCordoba = new Coordinate(-31.425299, -64.201743);\n\n/* Distance between Dresden, Germany and Córdoba, Argentina */\nprint $coordinate-\u003egetDistance($coordinateCordoba, Coordinate::RETURN_KILOMETERS);\n// (float) 11904.668\n```\n\n### 1.4 Direction example (degree)\n\n```php\n$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E');\n$coordinateCordoba = new Coordinate(-31.425299, -64.201743);\n\n/* Direction in degrees from Dresden, Germany to Córdoba, Argentina */\nprint $coordinateDresden-\u003egetDegree($coordinateCordoba);\n// (float) -136.62°\n```\n\n### 1.5 Direction example (cardinal direction)\n\n```php\n$coordinateDresden = new Coordinate('51°3′1.44″N 13°44′14.28″E');\n$coordinateCordoba = new Coordinate(-31.425299, -64.201743);\n\n/* Direction in degrees from Dresden, Germany to Córdoba, Argentina */\nprint $coordinateDresden-\u003egetDirection($coordinateCordoba);\n// (string) SW\n```\n\n## 2. Parser\n\n### 2.1 Basic decimal degree parser\n\n#### 2.1.1 Parser formats\n\n| Given value (string)              | Latitude (float) | Longitude (float) | Place              |\n|-----------------------------------|------------------|-------------------|--------------------|\n| `\"51.0504,13.7373\"`               | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"51.0504, 13.7373\"`              | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"51.0504 13.7373\"`               | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"POINT(-31.425299, -64.201743)\"` | _-31.425299_     | _-64.201743_      | Córdoba, Argentina |\n| `\"POINT(-31.425299 -64.201743)\"`  | _-31.425299_     | _-64.201743_      | Córdoba, Argentina |\n\n#### 2.1.2 Code example\n\n```php\n$coordinate = new Coordinate('51.0504 13.7373');\n\nprint $coordinate-\u003egetLatitude();\n// (float) 51.0504\n\nprint $coordinate-\u003egetLongitude();\n// (float) 13.7373\n```\n\n### 2.2 Basic DMS Parser\n\n#### 2.2.1 Parser formats\n\n| Given value (string)                       | Latitude (float) | Longitude (float) | Place              |\n|--------------------------------------------|------------------|-------------------|--------------------|\n| `\"51°3′1.44″N,13°44′14.28″E\"`              | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"51°3′1.44″N, 13°44′14.28″E\"`             | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"51°3′1.44″N 13°44′14.28″E\"`              | _51.0504_        | _13.7373_         | Dresden, Germany   |\n| `\"POINT(31°25′31.0764″S, 64°12′6.2748″W)\"` | _-31.425299_     | _-64.201743_      | Córdoba, Argentina |\n| `\"POINT(31°25′31.0764″S 64°12′6.2748″W)\"`  | _-31.425299_     | _-64.201743_      | Córdoba, Argentina |\n\n#### 2.2.2 Code example\n\n```php\n$coordinate = new Coordinate('51°3′1.44″N 13°44′14.28″E');\n\nprint $coordinate-\u003egetLatitude();\n// (float) 51.0504\n\nprint $coordinate-\u003egetLongitude();\n// (float) 13.7373\n```\n\n### 2.3 Google Url Parser Parser\n\n#### 2.3.1 Parser formats\n\n| Given value (string)                                   | Latitude (float) | Longitude (float) | Place            |\n|--------------------------------------------------------|------------------|-------------------|------------------|\n| Copied Google Maps Short Url\u003csup\u003e\u003ccode\u003e1)\u003c/code\u003e\u003c/sup\u003e | _54.07304830_    | _18.992402_       | Malbork, Poland  |\n| Copied Google Maps Link\u003csup\u003e\u003ccode\u003e2)\u003c/code\u003e\u003c/sup\u003e      | _51.31237_       | _12.4132924_      | Leipzig, Germany |\n\n* \u003csup\u003e\u003ccode\u003e1)\u003c/code\u003e\u003c/sup\u003e [Copied Google Maps Short Url](https://maps.app.goo.gl/PHq5axBaDdgRWj4T6)\n* \u003csup\u003e\u003ccode\u003e2)\u003c/code\u003e\u003c/sup\u003e [Copied Google Maps Link](https://www.google.com/maps/place/V%C3%B6lkerschlachtdenkmal,+04277+Leipzig/@51.3123709,12.4132924,17z/data=!3m1!4b1!4m6!3m5!1s0x47a6f9a9d013ca23:0x277b49a142da988c!8m2!3d51.3123709!4d12.4132924!16s%2Fg%2F12ls2f87w?entry=ttu)\n\n#### 2.3.2 Code example\n\n```php\n$coordinate = new Coordinate('https://maps.app.goo.gl/PHq5axBaDdgRWj4T6');\n\nprint $coordinate-\u003egetLatitude();\n// (float) 54.07304830\n\nprint $coordinate-\u003egetLongitude();\n// (float) 18.992402\n```\n\n## 3. Converter\n\n### 3.1 Methods of class `Coordinate`\n\n| Method                 | Type     | Parameter(s)                                           | Description                                                                                                      | Example                                                                                                                    |\n|------------------------|----------|--------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|\n| `getLatitude`          | _float_  | ---                                                    | Returns the decimal degree presentation of latitude value.                                                       | _-31.425299_                                                                                                               |\n| `getLongitude`         | _float_  | ---                                                    | Returns the decimal degree presentation of longitude value.                                                      | _-64.201743_                                                                                                               |\n| `getLatitudeDD`        | _float_  | ---                                                    | Alias of `getLatitude`.                                                                                          | _-31.425299_                                                                                                               |\n| `getLongitudeDD`       | _float_  | ---                                                    | Alias of `getLongitude`.                                                                                         | _-64.201743_                                                                                                               |\n| `getLatitudeDMS`       | _string_ | ---                                                    | Returns the dms representation of the latitude value.                                                            | `\"31°25′31.0764″S\"`                                                                                                        |\n| `getLongitudeDMS`      | _string_ | ---                                                    | Returns the dms representation of the longitude value.                                                           | `\"64°12′6.2748″W\"`                                                                                                         |\n| `getLatitudeDMS`       | _string_ | `CoordinateValue::FORMAT_DMS_SHORT_2`                  | Returns the dms representation of the latitude value (v2).                                                       | `\"S31°25′31.0764″\"`                                                                                                        |\n| `getLongitudeDMS`      | _string_ | `CoordinateValue::FORMAT_DMS_SHORT_2`                  | Returns the dms representation of the longitude value (v2).                                                      | `\"W64°12′6.2748″\"`                                                                                                         |\n| `getDistance`          | _float_  | `new Coordinate()`, `meters` (default) or `kilometers` | Returns the distance to given second Coordinate instance.                                                        | _11904.668_                                                                                                                |\n| `getDegree`            | _float_  | `new Coordinate()`                                     | Returns the direction (degree) to given second Coordinate instance (0° - North, 90° - East, etc.).               | _-136.62_                                                                                                                  |\n| `getDirection`         | _string_ | `new Coordinate()`                                     | Returns the cardinal direction to given second Coordinate instance (`N`, `NE`, `E`, `SE`, `S`, `SW`, `W`, `NW`). | `\"SW\"`                                                                                                                     |\n| `getLinkGoogle`        | _string_ | `false` (default - as decimal) or `true` (as DMS)      | Returns the link to Google.                                                                                      | [Google](https://www.google.de/maps/place/51.050400+13.737300)                                                             |\n| `getLinkOpenStreetMap` | _string_ | ---                                                    | Returns the link to OpenStreetMap.                                                                               | [OpenStreetMap](https://www.openstreetmap.org/?lat=51.050400\u0026lon=13.737300\u0026mlat=51.050400\u0026mlon=13.737300\u0026zoom=14\u0026layers=M) |\n\n### 3.2 Code example\n\n```php\n$coordinate = new Coordinate('-31.425299, -64.201743');\n\nprint $coordinate-\u003egetLatitudeDMS();\n// (string) \"31°25′31.0764″S\"\n\nprint $coordinate-\u003egetLongitudeDMS();\n// (string) \"64°12′6.2748″W\"\n```\n\n## 4. Installation\n\n```bash\ncomposer require ixnode/php-coordinate\n```\n\n```bash\nvendor/bin/php-coordinate -V\n```\n\n```bash\nphp-coordinate 0.1.0 (03-07-2023 01:17:26) - Björn Hempel \u003cbjoern@hempel.li\u003e\n```\n\n## 5. Command line tool\n\n\u003e Used to quickly check two given coordinates.\n\nCheck _Dresden, Germany_ and _New York, United States_:\n\n```bash\nbin/console pc \"51°3′1.44″N, 13°44′14.28″E\" \"40.712784, -74.005941\"\n```\n\nor within your composer project:\n\n```bash\nvendor/bin/php-coordinate pc \"51°3′1.44″N, 13°44′14.28″E\" \"40.712784, -74.005941\"\n```\n\n```bash\n\nSource coordinate (51°3′1.44″N, 13°44′14.28″E):\n\n+---------+------------------+--------------------+\n| Value   | Latitude         | Longitude          |\n+---------+------------------+--------------------+\n| Decimal | 51.0504          | 13.7373            |\n| DMS     | 51°3′1.44″N      | 13°44′14.28″E      |\n+---------+------------------+--------------------+\n\nTarget coordinate (40.712784, -74.005941):\n\n+---------+----------------------+---------------------+\n| Value   | Latitude             | Longitude           |\n+---------+----------------------+---------------------+\n| Decimal | 40.712784            | -74.005941          |\n| DMS     | 40°42′46.0224″N      | 74°0′21.3876″W      |\n+---------+----------------------+---------------------+\n\nDistance:\n\n+-----------+-------------+\n| Key       | Value       |\n+-----------+-------------+\n| Distance  | 6478.472 km |\n| Degree    | -96.720°    |\n| Direction | W           |\n+-----------+-------------+\n\n+--------------------------------------------------------------------------------+\n|                                   World map                                    |\n+--------------------------------------------------------------------------------+\n|                                                                                |\n|                     ▄▄▄▄▀▄▄▄▄▄▄▄▄▄▄                                            |\n|       ▄▄    ▄▄▄▄▄▄▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀                ▄▄▄▄▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄          |\n|  ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀      ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀  |\n| ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀   ▀▀          ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀   |\n|       ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀           ▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄ ▀▀    |\n|     ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀            ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀       |\n|     ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀               ▀▀▀▀▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄        |\n|     ▀▀▀▀▀▀▀▀▀▀▀▀                 ▀▀▀▀▀▀▀▀▀▀▄▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀        |\n|      ▀▀▀▀▀▀▄▄ ▀                ▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀         |\n|        ▀▀▀▀▀▀                  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀▀▀           |\n|           ▀▀▀▄▄▀▀▄▄▄           ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀      ▀▀    ▀▀▀▀            |\n|              ▀▀▀▀▀▀▀▀▀▄         ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀            ▀▄  ▄▀▀         |\n|              ▀▀▀▀▀▀▀▀▀▀▀▄▄▄           ▀▀▀▀▀▀▀▀▀▀▀              ▀▀▀▀▀▀▀   ▀▄▄▄▄ |\n|              ▀▀▀▀▀▀▀▀▀▀▀▀▀▀            ▀▀▀▀▀▀▀▀▀                 ▀        ▀▀▀▀▄|\n|               ▀▀▀▀▀▀▀▀▀▀▀▀             ▀▀▀▀▀▀▀▀▀▄▀▀                   ▄▀▀▀▀▀▀  |\n|                  ▀▀▀▀▀▀▀▀▀             ▀▀▀▀▀▀▀▀ ▀▀                 ▀▀▀▀▀▀▀▀▀▀▀ |\n|                  ▀▀▀▀▀▀▀                ▀▀▀▀▀▀  ▀                  ▀▀▀▀▀▀▀▀▀▀▀ |\n|                  ▀▀▀▀▀▀                  ▀▀▀                       ▀▀▀▀▀▀▀▀▀▀▀ |\n|                  ▀▀▀▀                                                     ▀    |\n|                   ▀▀▀                                                          |\n+--------------------------------------------------------------------------------+\n\n+------------------------------------+   +---------------------------------------+\n|         Cardinal direction         |   |         Longitude / Langitude         |\n+------------------------------------|   +---------------------------------------|\n|                                    |   |          lat                          |\n|                  0°                |   |                                       |\n|                                    |   |       90° ⯅                           |\n|                 ___                |   |           |                           |\n|    -45°         ───        45°     |   |           |                           |\n|          //      N      \\\\         |   |           |   • Oslo (59.91°, 10.75°) |\n|             NW       NE            |   |           | • London (51.51°, -0.13°) |\n|                  |                 |   |    • New York (40.71°, -74.01°)       |\n|  -90°  || W    --+--    E ||  90°  |   |           |                           |\n|                  |                 |   |           |                           |\n|             SW       SE            |   |           |                           |\n|          \\\\      S      //         |   |           | • Null Island (0°, 0°)    |\n|    -135°        ───        135°    |   |   ⯇-------+-------------------⯈  lon  |\n|                 ‾‾‾                |   |  -180°    |                 180°      |\n|                                    |   |           |                           |\n|                 180°               |   |           |       • Cape Agulhas      |\n|                                    |   |      -90° ⯆         (-34.82°, 20.02°) |\n+------------------------------------+   +---------------------------------------+\n\n```\n\n\u003cimg src=\"docs/image/world-map-cli.png\" alt=\"Services\" width=\"800\"/\u003e\n\n## 6. Library development\n\n```bash\ngit clone git@github.com:ixnode/php-coordinate.git \u0026\u0026 cd php-coordinate\n```\n\n```bash\ncomposer install\n```\n\n```bash\ncomposer test\n```\n\n## 7. License\n\nThis library is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixnode%2Fphp-coordinate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fixnode%2Fphp-coordinate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixnode%2Fphp-coordinate/lists"}