A function that calculates the distance between two geographic points given their latitude and longitude coordinates.
Addendum: The use of the Haversine formula for distance calculation was suggested by ChatGPT. The Haversine formula was chosen because it accounts for the curvature of the Earth, providing an accurate “great-circle” distance between two points given their latitude and longitude, rather than assuming a flat surface.
Parameters
Name
Type
Description
Default
latitude_1
float
Latitude of the first point in degrees (-90 to 90)
required
longitude_1
float
Longitude of the first point in degrees (-180 to 180)
required
latitude_2
float
Latitude of the second point in degrees (-90 to 90)
required
longitude_2
float
Longitude of the second point in degrees (-180 to 180)
required
Returns
Name
Type
Description
distance
float
Distance between the two points (in kilometers)
Raises
Name
Type
Description
ValueError
If any latitude is outside [-90, 90] or any longitude is outside [-180, 180].