PHP Coordinate
Abstract: This PHP Composer library offers a collection of various PHP coordinate classes like Coordinate, etc. It converts various coordinate strings and values into a unique format.
You work with geographic coordinates in different formats (sexagesimal, decimal). You want to parse or convert them. Then the following library could be the right one for you if you work within a PHP Composer project:
Easy to install via:
composer require ixnode/php-coordinate
You can then convert coordinates, parse, calculate distance, direction, etc:
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
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
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
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°
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
Finally
For more information, examples and the description of a cool integrated command line tool, see PHP Coordinate.
Quote
Never Send a Human to do a Machine's Job