class Distance implements DistanceInterface

Properties

protected CoordinatesInterface $from

The origin coordinate.

protected CoordinatesInterface $to

The destination coordinate.

protected string $unit

The user unit.

protected array $data

Methods

setFrom(CoordinatesInterface $from)

Set the origin coordinate

getFrom()

Get the origin coordinate

setTo(CoordinatesInterface $to)

Set the destination coordinate

getTo()

Get the destination coordinate

in(string $unit)

Set the user unit

string
getUnit()

Get the user unit

withData(string $name, mixed $value)

No description

mixed
getData(string $name, mixed|null $default = null)

No description

float
flat()

Returns the approximate flat distance between two coordinates using Pythagoras’ theorem which is not very accurate.

float
greatCircle()

Returns the approximate distance between two coordinates using the spherical trigonometry called Great Circle Distance.

haversine()

Returns the approximate sea level great circle (Earth) distance between two coordinates using the Haversine formula which is accurate to around 0.3%.

float
vincenty()

Returns geodetic distance between between two coordinates using Vincenty inverse formula for ellipsoids which is accurate to within 0.5mm.

float
convertToUserUnit(float $meters)

Converts results in meters to user's unit (if any).

Details

at line 39
DistanceInterface setFrom(CoordinatesInterface $from)

Set the origin coordinate

Parameters

CoordinatesInterface $from

The origin coordinate

Return Value

DistanceInterface

at line 49
CoordinatesInterface getFrom()

Get the origin coordinate

Return Value

CoordinatesInterface

at line 57
DistanceInterface setTo(CoordinatesInterface $to)

Set the destination coordinate

Parameters

CoordinatesInterface $to

The destination coordinate

Return Value

DistanceInterface

at line 67
CoordinatesInterface getTo()

Get the destination coordinate

Return Value

CoordinatesInterface

at line 75
DistanceInterface in(string $unit)

Set the user unit

Parameters

string $unit

Set the unit

Return Value

DistanceInterface

at line 82
string getUnit()

Get the user unit

Return Value

string

at line 93
DistanceInterface withData(string $name, mixed $value)

No description

Parameters

string $name
mixed $value

Return Value

DistanceInterface

at line 106
mixed getData(string $name, mixed|null $default = null)

No description

Parameters

string $name
mixed|null $default

Return Value

mixed

at line 123
float flat()

Returns the approximate flat distance between two coordinates using Pythagoras’ theorem which is not very accurate.

at line 148
float greatCircle()

Returns the approximate distance between two coordinates using the spherical trigonometry called Great Circle Distance.

at line 174
haversine()

Returns the approximate sea level great circle (Earth) distance between two coordinates using the Haversine formula which is accurate to around 0.3%.

at line 199
float vincenty()

Returns geodetic distance between between two coordinates using Vincenty inverse formula for ellipsoids which is accurate to within 0.5mm.

Return Value

float

The distance in meters

See also

http://www.movable-type.co.uk/scripts/latlong-vincenty.html

at line 267
float convertToUserUnit(float $meters)

Converts results in meters to user's unit (if any).

The default returned value is in meters.

Parameters

float $meters

Return Value

float