How to Calculate distance between two address using latitude and longitude.

Code

How to Calculate distance between two address using latitude and longitude.

According To me it’s one of important requirement in many projects related to address. To Calculate distance between two address using latitude and longitude use this method.

function LongLatDistance($Latitude1, $Longitude1, $Latitude2, $Longitude2) {
$theta = $Longitude1 - $Longitude2;
$miles = (sin(deg2rad($Latitude1))*sin(deg2rad($Latitude2)))+(cos(deg2rad($Latitude1))*cos(deg2rad($Latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$result['miles'] = $miles * 60 * 1.1515;
$result['feet'] = $result['miles'] * 5280;
$result['yards'] = $result['feet'] / 3;
$result['kilometers'] = $result['miles'] * 1.609344;
$result['meters'] = $result['kilometers'] * 1000;
return $result;
}
$distance = LongLatDistance($lat1='27.3766', $lon1='75.5580', $lat2='26.9124', $lon1='75.7873' );
var_dump($distance);

OUTPUT
array(5) {
["miles"]=>float(35.033155471693)
["feet"]=>float(184975.06089054)
["yards"]=>float(61658.35363018)
["kilometers"]=>float(56.380398559437)
["meters"]=>float(56380.398559437)
}

Enjoy.

Shiv kumawat

Executive Director & CEO

"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.”

Latest Posts

Generative AR Shopping Apps 2026 67% Conversion Boost

  AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide) The 73% Cart Abandonment Problem You’re Solving…

Shafeeq Khan
January 31, 2026

AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide)

  AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide) The $2.3M ARR Problem You’re Solving  …

Shafeeq Khan
January 30, 2026

Top 12 AI App Development Trends 2026 Build $10M ARR Apps Agencies Are Charging $500K To Create

  Top 12 AI App Development Trends 2026 Build $10M ARR Apps Agencies Are Charging $500K To Create Trend #1…

Shafeeq Khan
January 26, 2026

Leave a Reply

Your email address will not be published. Required fields are marked *