How to calculate distance between two lat long in php

hi I want to find out distance between from latitude & longitude to latitude & longitude, for example distance between mumbai to delhi in php.
Deepak Sharma
Asked 06-01-2021
42

Answer (1)
hello here is your solution, <?php function distance_bt_two_points($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) { $longitude1 = deg2rad($longitudeFrom); $longitude2 = deg2rad($longitudeTo); $latitude1 = deg2rad($latitudeFrom); $latitude2 = deg2rad($latitudeTo); //Haversine Formula $dlong = $longitude2 - $longitude1; $dlati = $latitude2 - $latitude1; $val = pow(sin($dlati/2),2)+cos($lat1)*cos($lat2)*pow(sin($dlong/2),2); $res = 2 * asin(sqrt($val)); $radius = 3958.756; return ($res*$radius); } $latitudeFrom = 19.017656 ; //mumbai $longitudeFrom = 72.856178; //mumbai $latitudeTo = 28.615338; //delhi $longitudeTo = 77.193474; //delhi // Distance between Mumbai and Delhi echo(distance_bt_two_points( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo)." "."miles"); ?> OUTPUT : 717.3753011057 miles
Ankur Rajput
Asked 02-03-2020
45 Likes
Comments
Write comment

Submit your answer