PHP code example of longitude-one / geo-parser

1. Go to this page and download the library: Download longitude-one/geo-parser 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/ */

    

longitude-one / geo-parser example snippets


use LongitudeOne\GeoParser\Parser;

$input  = '79°56′55″W, 40°26′46″N';

$parser = new Parser($input);

$value = $parser->parse(); // [-79.948611111111, 40.446111111111]

use LongitudeOne\GeoParser\Parser;

$input1 = '56.242 E';
$input2 = '40:26:46 S';

$parser = new Parser();

$value1 = $parser->parse($input1); //56.242
$value2 = $parser->parse($input2); //-40.446111111111

use LongitudeOne\Core\Enum\AxisEnum;
use LongitudeOne\GeoParser\Coordinate;
use LongitudeOne\GeoParser\Parser;
use LongitudeOne\GeoParser\Point;

$coordinate = (new Parser('40°26\'46"N'))->parseAsCoordinates();

assert($coordinate instanceof Coordinate);
assert(40.44611111111111 === $coordinate->getValue());
assert(AxisEnum::LATITUDE === $coordinate->getAxis());

$point = (new Parser('79°56\'55"W, 40°26\'46"N'))->parseAsCoordinates();

assert($point instanceof Point);
assert(-79.94861111111111 === $point->getFirst()->getValue());
assert(AxisEnum::LONGITUDE === $point->getFirst()->getAxis());
assert(AxisEnum::LATITUDE === $point->getSecond()->getAxis());

use LongitudeOne\GeoParser\Exception\ExceptionInterface;
use LongitudeOne\GeoParser\Parser;

try {
    $value = (new Parser('100N'))->parse();
} catch (ExceptionInterface $exception) {
    // Handle a library parsing exception.
}