Skip to content

Commit

Permalink
Added functions for calculating bearing / direction from point A to p…
Browse files Browse the repository at this point in the history
…oint B
  • Loading branch information
weejames committed Apr 24, 2011
1 parent cefcfdf commit 8e6d603
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libraries/geotools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

class Geotools {

private $defaultUnit = 'km';
private $defaultUnit = 'miles';
private $kmPerMile = 1.609;
private $earthRadius = array();
private $directions = array("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N");

public function __construct() {
$this->earthRadius['miles'] = 3963.19;
Expand All @@ -28,7 +29,6 @@ public function distanceBetween(Geopoint $pointA, Geopoint $pointB, $algorithm =
$distanceEW = ($pointB->longitude - $pointA->longitude) * cos($pointA->latitude);
$distanceNS = $pointB->latitude - $pointA->latitude;


$distance = sqrt( ($distanceEW * $distanceEW) + ($distanceNS * $distanceNS));
break;
}
Expand All @@ -38,6 +38,15 @@ public function distanceBetween(Geopoint $pointA, Geopoint $pointB, $algorithm =
return $distance;

}


public function compassDirection(Geopoint $pointA, Geopoint $pointB) {
$bearing = $this->bearingFrom($pointA, $pointB);

$tmp = round($bearing / 22.5);

return $this->directions[$tmp];
}

public function geopoint($latitude, $longitude) {
include_once('geopoint.php');
Expand Down

0 comments on commit 8e6d603

Please sign in to comment.