GeoUnit
The unit a distance is given or asked for in.
The same stretch of the globe is one number in kilometres and another in miles.
Nothing in a bare float says which one you mean — so the distance methods on
CkGeo ask you, with a GeoUnit parameter. Leave it out and everything is
kilometres. It lives in SafeCoder\CommonKit\Enums, an int-backed enum.
Members
| Member | Meaning |
|---|---|
Kilometers |
Kilometres. This is the default. |
Miles |
Statute miles — the ordinary mile used on US roads. |
NauticalMiles |
Nautical miles — one minute of latitude (a sixtieth of a degree). |
Meters |
Metres. |
Where it is used
Four methods on CkGeo take a unit parameter. On
Distance it sets the unit of the answer; on IsWithin it sets the unit of
the radius you pass in, on BoundsAround the unit of the radius the box is drawn
around, and on Destination the unit of the distance travelled. All four default to
GeoUnit::Kilometers.
Quick look
use SafeCoder\CommonKit\CkGeo;
use SafeCoder\CommonKit\Enums\GeoUnit;
// New York to London, along the surface of the globe
CkGeo::Distance(
latitude1: 40.7128,
longitude1: -74.0060,
latitude2: 51.5074,
longitude2: -0.1278
); // -> 5570.229873656523 (kilometres, the default)
CkGeo::Distance(
latitude1: 40.7128,
longitude1: -74.0060,
latitude2: 51.5074,
longitude2: -0.1278,
unit: GeoUnit::Miles
); // -> 3461.1803776299676