PHP code example of stanislav-janu / gps

1. Go to this page and download the library: Download stanislav-janu/gps 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/ */

    

stanislav-janu / gps example snippets


use JanuSoftware\GPS\GpsPoint;
use JanuSoftware\GPS\GpsPointException;

try {
    $point = GpsPoint::from('49°3\'6.630"N, 14°26\'7.763"E');
    echo $point; // 49.0518417, 14.4354897
    echo $point->lat; // 49.0518417
    echo $point->lng; // 14.4354897
} catch (GpsPointException $exception) {
    echo $exception->getMessage();
}

$point1 = GpsPoint::from('some coordinates');
$point2 = GpsPoint::from('some coordinates');
$distance =  $point1->distanceTo($point2); // distance in meters

...
$distance = $point1->distanceTo($point2, 'Google Maps API key'); // distance in meters