GPS坐标的简单包装器

1.0.0 2020-07-08 21:22 UTC

This package is auto-updated.

Last update: 2024-09-09 06:31:25 UTC


README

GPS坐标的简单包装器。提供基本功能,如计算两点之间的距离、给定两点之间坐标的插值以及反极点计算。它使用bcmath PHP扩展进行计算(仅适用于合格的计算)。

安装

使用composer

composer require goosfraba/gps

使用方法

坐标实例化和基本使用

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();

计算两点之间的距离

use Goosfraba\Gps\GpsCoordinates;

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

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

在给定距离的两点之间进行坐标插值

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);

反极点计算

use Goosfraba\Gps\GpsCoordinates;

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

测试

./vendor/bin/phpunit