File modules/util/Coordinates.class.php

Last commit: Mon Apr 22 22:29:49 2024 +0200	Jan Dankert	Editing coordinates now possible.
1 <?php 2 namespace util; 3 4 class Coordinates 5 { 6 private $lat; 7 private $long; 8 9 const FORMAT_WGS84_DEGREES = 1; 10 const FORMAT_WGS84_DEGREES_MINUTES = 2; 11 const FORMAT_WGS84_DEGREES_MINUTES_SECONDS = 3; 12 const FORMAT_UTM = 4; 13 const FORMAT_PLUSCODE = 5; 14 15 /** 16 * @param $long 17 * @param $lat 18 */ 19 public function __construct($long, $lat) 20 { 21 $this->lat = $lat; 22 $this->long = $long; 23 } 24 25 public function __toString() 26 { 27 return "".$this->lat."° ".$this->long."°"; 28 } 29 30 public function format( $type ) 31 { 32 switch( $type ) { 33 case self::FORMAT_WGS84_DEGREES: 34 default: 35 return "".abs($this->lat)."°".($this->lat<0?"S":"N").", ".abs($this->long)."°".($this->long<0?"W":"E"); 36 } 37 } 38 39 40 /** 41 * @param $otherCoordinates Coordinates 42 * @return float|int 43 */ 44 function distanceTo($otherCoordinates) { 45 if (($this->lat == $otherCoordinates->lat) && ($this->long == $otherCoordinates->long)) { 46 return 0; 47 } 48 else { 49 $theta = $this->long - $otherCoordinates->long; 50 $dist = sin(deg2rad($this->lat)) * sin(deg2rad($otherCoordinates->lat)) + cos(deg2rad($this->lat)) * cos(deg2rad($otherCoordinates->lat)) * cos(deg2rad($theta)); 51 $dist = acos($dist); 52 $dist = rad2deg($dist); 53 $miles = $dist * 60 * 1.1515; 54 55 //return ($miles * 1.609344); // KM 56 return $miles; // miles 57 } 58 } 59 }
Download modules/util/Coordinates.class.php
History Mon, 22 Apr 2024 22:29:49 +0200 Jan Dankert Editing coordinates now possible. Wed, 17 Apr 2024 00:34:07 +0200 Jan Dankert New: Inputfields for coordinates; coordinates are stored in the now 64bit-number-field of the value.