Gps Koordinatları Arasındaki Mesafeyi Hesaplamak

<?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

 

Google Map Koordinat Bulucu

<?php

if($_POST){
print_r($_POST);
exit;
}
?>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Map Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script>
<script type="text/javascript">
  
  var placeSearch,autocomplete;
  var component_form = {
    'street_number': 'short_name',
    'route': 'long_name',
    'locality': 'long_name',
    'country': 'long_name',
    'postal_code': 'short_name'
  };
  
  function initialize() {
    autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete'), { types: [ 'geocode' ] });
    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      fillInAddress();
    });
  }
  
  function fillInAddress() {
    var place = autocomplete.getPlace();
	var lat = place.geometry.location.lat();
	var lng = place.geometry.location.lng();
    for (var component in component_form) {
      document.getElementById(component).value = "";
      document.getElementById(component).disabled = false;
	document.getElementById("long").value = lng;
	document.getElementById("lat").value = lat;
    }
    
    for (var j = 0; j < place.address_components.length; j++) {
      var att = place.address_components[j].types[0];
      if (component_form[att]) {
        var val = place.address_components[j][component_form[att]];
        document.getElementById(att).value = val;
      }
    }
  }
    
  function geolocate() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var geolocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
        autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation));
      });
    }
  }

</script>
</head>
<body onload="initialize()">
	
  <div id="locationField">
    <input id="autocomplete" placeholder="Adresinizi Giriniz" onFocus="geolocate()" type="text"></input>
  </div>
  <form action="streetfindexportinput.php" method="post">
	Sokak No:<input id="street_number" disabled="true"/><br>
	Güzergah:<input id="route" disabled="true"/><br>
    Semt:<input id="locality" disabled="true"/><br>
    Posta<input id="postal_code" disabled="true"/><br>
    Ülke<input id="country" disabled="true"/><br>
    <input type="hidden" name="lng"  id="long" />
    <input type="hidden" name="lat"  id="lat" />
   <button type="submit">Gönder</button>
	</form>
	
  </body>
</html>