This library offers a collection of various PHP coordinate classes like Coordinate, etc. It converts various coordinate strings and values into a unique format.
use Ixnode\PhpCoordinate\Coordinate;$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$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$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$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Β°$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| 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 |
$coordinate = new Coordinate('51.0504 13.7373');
print $coordinate->getLatitude();
// (float) 51.0504
print $coordinate->getLongitude();
// (float) 13.7373| 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 |
$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| 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 |
$coordinate = new Coordinate('https://maps.app.goo.gl/PHq5axBaDdgRWj4T6');
print $coordinate->getLatitude();
// (float) 54.07304830
print $coordinate->getLongitude();
// (float) 18.992402| 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. | |
getLinkOpenStreetMap |
string | --- | Returns the link to OpenStreetMap. | OpenStreetMap |
$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"composer require ixnode/php-coordinatevendor/bin/php-coordinate -Vphp-coordinate 0.1.0 (03-07-2023 01:17:26) - BjΓΆrn Hempel <bjoern@hempel.li>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 |
| 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Β°) |
+------------------------------------+ +---------------------------------------+
git clone git@github.com:ixnode/php-coordinate.git && cd php-coordinatecomposer installcomposer testThis library is licensed under the MIT License - see the LICENSE file for details.
