geolocation_bounds.php 774 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class GeolocationBounds {
  3. protected $minLat = 180;
  4. protected $minLng = 180;
  5. protected $maxLat = -180;
  6. protected $maxLng = -180;
  7. public function __construct() {
  8. }
  9. public function extend($lat, $lng) {
  10. if($lat > $this->maxLat) $this->maxLat = $lat;
  11. if($lng > $this->maxLng) $this->maxLng = $lng;
  12. if($lat < $this->minLat) $this->minLat = $lat;
  13. if($lng < $this->minLng) $this->minLng = $lng;
  14. }
  15. public function getCenter() {
  16. return $this->getCentre();
  17. }
  18. public function getCentre() {
  19. return [
  20. ($this->minLat + $this->maxLat) / 2,
  21. ($this->minLng + $this->maxLng) / 2,
  22. ];
  23. }
  24. public function getSouthWest() {
  25. return [$this->minLat, $this->minLng];
  26. }
  27. public function getNorthEast() {
  28. return [$this->maxLat, $this->maxLng];
  29. }
  30. }