ユーザーから2つの地理座標を取得し、それらの間の距離を計算する小さなプログラムを設定しています(地球の曲率を考慮に入れて)。だから私は式がここにあるものについてウィキペディアを調べました。
私は基本的にそれに基づいてPython関数を設定し、これが私が思いついたものです:
def geocalc(start_lat, start_long, end_lat, end_long):
start_lat = math.radians(start_lat)
start_long = math.radians(start_long)
end_lat = math.radians(end_long)
end_long = math.radians(end_long)
d_lat = start_lat - end_lat
d_long = start_long - end_long
EARTH_R = 6372.8
c = math.atan((math.sqrt( (math.cos(end_lat)*d_long)**2 +( (math.cos(start_lat)*math.sin(end_lat)) - (math.sin(start_lat)*math.cos(end_lat)*math.cos(d_long)))**2)) / ((math.sin(start_lat)*math.sin(end_lat)) + (math.cos(start_lat)*math.cos(end_lat)*math.cos(d_long))) )
return EARTH_R*c
問題は、結果が本当に不正確になることです。私はPythonを初めて使用するので、ヘルプやアドバイスをいただければ幸いです。