A simple wrapper for GPS coordinates

1.0.0 2020-07-08 21:22 UTC

This package is auto-updated.

Last update: 2024-10-09 06:38:46 UTC


README

A simple wrapper for GPS coordinates. Provides basic functionalities like distance calculation between two givens points, interpolation of the coordinates between two givens points and antipodes calculation. It uses bcmath PHP extension for calculation (for eligible calculations only).

Installation

Use composer

composer require goosfraba/gps

Usage

Coordinates instantiation and basic usage

use Goosfraba\Gps\GpsCoordinates;
$coordinates = GpsCoordinates::createFromDegrees(38.8, -77.1);
// or
$coordinates = GpsCoordinates::createFromRadians(0.677187749773799875846392, -1.3456488532876281038081655);

// accessing coordinates in radians
$latitudeInRadians = $coordinates->latitudeInRadians();
$longitudeInRadians = $coordinates->longitudeInRadians();

// accessing coordinates in degrees
$latitudeInDegrees = $coordinates->latitudeInDegrees();
$longitudeInDegrees = $coordinates->longitudeInDegrees();

Calculating distance between two givens points

use Goosfraba\Gps\GpsCoordinates;

$coordinate1 = GpsCoordinates::createFromDegrees(51.5, 0);
$coordinate2 = GpsCoordinates::createFromDegrees(38.8, -77.1);

$distanceInMeters = $coordinate1->disntaceTo($coordinate2);

Coordinates interpolation between two givens points at given distance

use Goosfraba\Gps\GpsCoordinates;

$coordinate1 = GpsCoordinates::createFromDegrees(51.5, 0);
$coordinate2 = GpsCoordinates::createFromDegrees(38.8, -77.1);

$midPointCoordinates = $coordinate1->pointBetween($coordinate2);
$coordinatesAt10Percent = $coordinate1->pointBetween($coordinate2, $coordinate1->distanceTo($coordinate2) / 10);

Antipodes calculation

use Goosfraba\Gps\GpsCoordinates;

$coordinate = GpsCoordinates::createFromDegrees(51.5, 0);
$antipodes = $coordinate->antipodes();

Tests

./vendor/bin/phpunit