PHP code example of ixnode / php-coordinate

1. Go to this page and download the library: Download ixnode/php-coordinate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ixnode / php-coordinate example snippets


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

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

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

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

$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

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

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

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

$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"
bash
composer 
bash
vendor/bin/php-coordinate -V
bash
php-coordinate 0.1.0 (03-07-2023 01:17:26) - Björn Hempel <[email protected]>
bash
vendor/bin/php-coordinate pc "51°3′1.44″N, 13°44′14.28″E" "40.712784, -74.005941"
bash
git clone [email protected]:ixnode/php-coordinate.git && cd php-coordinate