import math
def haversine(lat1, lon1, lat2, lon2):
# Radius of the Earth in kilometers
radius = 6371.0
# Convert latitude and longitude from degrees to radians
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
lat2 = math.radians(lat2)
lon2 = math.radians(lon2)
# Haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat / 2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
# Calculate the distance
distance = radius * c
return distance
# Example coordinates for two sites
site1_lat = 40.7128 # Latitude of site 1 (e.g., New York City)
site1_lon = -74.0060 # Longitude of site 1
site2_lat = 34.0522 # Latitude of site 2 (e.g., Los Angeles)
site2_lon = -118.2437 # Longitude of site 2
# Calculate the distance between the two sites
distance_km = haversine(site1_lat, site1_lon, site2_lat, site2_lon)
print(f"The distance between the two sites is {distance_km:.2f} kilometers.")