MAPG-6 introduce and unify geo calculations

This commit is contained in:
bence committed 2020-05-19 19:01:35 +02:00
1 parent 1d4bfd75d8
commit e15421af8b
3 files changed
+42 -9

No files matched your search

+15 -1
View File
@@ -2,6 +2,8 @@
class Bounds
{
const ONE_DEGREE_OF_LATITUDE_IN_METER = 111132.954;
private float $southLat;
private float $westLng;
@@ -19,7 +21,7 @@ class Bounds
return $instance;
}
public static function createDirectly(float $southLat, $westLng, $northLat, $eastLng): Bounds
public static function createDirectly(float $southLat, float $westLng, float $northLat, float $eastLng): Bounds
{
$instance = new static();
@@ -61,6 +63,18 @@ class Bounds
}
}
public function calculateApproximateArea(): float
{
$dLat = $this->northLat - $this->southLat;
$dLng = $this->eastLng - $this->westLng;
$m = $dLat * static::ONE_DEGREE_OF_LATITUDE_IN_METER;
$a = $dLng * static::ONE_DEGREE_OF_LATITUDE_IN_METER * cos(deg2rad($this->northLat));
$c = $dLng * static::ONE_DEGREE_OF_LATITUDE_IN_METER * cos(deg2rad($this->southLat));
return $m * ($a + $c) / 2;
}
public function toJson(): string
{
if (!$this->initialized) {