python: python input the coordinates of the position (ie longitude and latitude), calculate the distance between two points and keep two digits

        The following is a Python code example that uses the geopy library to calculate the distance between two coordinates and rounds the result to two decimal places:

from geopy.distance import geodesic

# 输入位置的经纬度
lat1, lon1 = 31.2233, 121.4554
lat2, lon2 = 40.7128, -74.0060

# 计算两点距离并保留两位小数
distance = round(geodesic((lat1, lon1), (lat2, lon2)).km, 2)

print("两点之间的距离为:", distance, "千米")

        The output is

两点之间的距离为: 11116.29 千米

Guess you like

Origin blog.csdn.net/SYC20110120/article/details/132639315