<?php class gpsMesafe { var $koordinat1; var $koordinat2; var $birim = NULL; var $formatla = NULL; function __construct($birim){ $this->birim=$birim; } public function calc(){ $radyan=57.2958;//derece $dunya=3958.75;//mil $acos=acos(sin($this->koordinat1[0]/$radyan)*sin($this->koordinat2[0]/$radyan)+cos($this->koordinat1[0]/$radyan)*cos($this->koordinat2[0]/$radyan)*cos($this->koordinat2[1]/$radyan-$this->koordinat1[1]/$radyan)); $fark=$dunya*$acos; switch ($this->birim){ default: case "": case "mil": $this->birim = "mil"; $fark = $fark * 1; break; case "yard": $this->birim = "yard"; $fark = $fark * 1760; break; case "parsec": $this->birim = "parsek"; $fark = $fark * 0.0000000000000521553443; break; case "denizmili": $this->birim = "denizmili"; $fark = $fark * 0.868974087; break; case "isikyili": $this->birim = "isikyili"; $fark = $fark * 0.0000000000001701114356; break; case "kilometre": $this->birim = "kilometre"; $fark = $fark * 1.609344; break; case "inç": $this->birim = "inç"; $fark = $fark * 63360; break; case "furlong": $this->birim = "Furlongs"; $fark = $fark * 8; break; case "adim": $this->birim = "adim"; $fark = $fark * 5280; break; } $this->formatla = $fark." ".$this->birim; return $fark; } } $distance = new gpsMesafe ("kilometre"); $distance->koordinat1=[89.98321, 21.951274]; $distance->koordinat2=[89.44865, 22.65947]; $distance->calc(); echo $distance->formatla; echo "<br>"; $distance->birim="mil"; $distance->calc(); echo $distance->formatla; ?>
Çıktısı
59.440398042875 kilometre 36.934550998963 mil