PHP-Code:
$arr2 = json_decode($json2);
$fahrzeug_lat= "$arr2->dec_lat";
$fahrzeug_long= "$arr2->dec_long";
$start_lat ="52";
$start_long = "8";
function distanceCalculation($point1_lat, $point1_long, $point2_lat, $point2_long, $unit = 'km', $decimals = 2) {
****
******** ****$degrees = rad2deg(acos((sin(deg2rad($point1_lat))*sin(deg2rad($point2_lat))) + (cos(deg2rad($point1_lat))*cos(deg2rad($point2_lat))*cos(deg2rad($point1_long-$point2_long)))));
******** ****switch($unit) {
******** **** **** ****case 'km':
******** **** **** **** **** ****$distance = $degrees * 111.13384;
******** **** **** **** **** ****break;
******** **** **** ****case 'mi':
******** **** **** **** **** ****$distance = $degrees * 69.05482;
******** **** **** **** **** ****break;
******** **** **** ****case 'nmi':
******** **** **** **** **** ****$distance = ****$degrees * 59.97662;
******** ****}
******** ****return round($distance, $decimals);
}
$point1 = array("lat" => $fahrzeug_lat, "long" => $fahrzeug_long);
$point2 = array("lat" => $start_lat, "long" => $start_long);
$km = distanceCalculation($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
$mi = distanceCalculation($point1['lat'], $point1['long'], $point2['lat'], $point2['long'], 'mi');
$nmi = distanceCalculation($point1['lat'], $point1['long'], $point2['lat'], $point2['long'], 'nmi');
echo $km;
Kommentar