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

Code

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.

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, the Jaipur-based IT company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

Isometric illustration of a business building with a location pin linked to a chat answer window that highlights one recommended listing, with review stars, documents and a magnifier

How to Get Your Business Recommended by ChatGPT in 2026

Ask ChatGPT for “the best web development company for a startup” or “a reliable app agency in India” and it…

Shafeeq Khan
October 23, 2026
Isometric illustration of an AI voice agent: a smartphone with a sound wave linked to a headset robot receptionist, a booking calendar and stacks of coins

AI Voice Agent Cost in 2026: Platforms vs a Custom Build

A missed call at a clinic, salon or service business is often a missed booking. That is why owners now…

Shafeeq Khan
October 22, 2026
Isometric illustration of an AI answer panel citing a business website, with an AI crawler and search pages connected to it, for an AEO services guide

AEO Services: Get Cited in ChatGPT and Google AI Overviews

When a buyer asks ChatGPT, Perplexity, Gemini or Google’s AI Overviews “who builds X in India?” or “what does Y…

Shafeeq Khan
October 19, 2026

Leave a Reply

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