程序如下:
import math
x1,y1 = eval(input(“Please input point1(latitude and longitude) in degrees:”))
x2,y2 = eval(input(“Please input point2(latitude and longitude) in degrees:”))
radius = 6371.01
x11 = math.radians(x1) #math.radians()函数将度数转换成弧度数
y11 = math.radians(y1)
x22 = math.radians(x2)
y22 = math.radians(y2)
d = radius * math.acos(math.sin(x11) * math.sin(x22) + math.cos(x11) * math.cos(x22) * math.cos(y11-y22))
print(“The distance between the two points is %5.2f km”%d)
程序运行结果: