私の仕事は、開始場所からFacebookから取得したすべてのイベント場所までの往復距離をマイル単位で計算し、開始に戻ることです。これまでの私のコード:
import json
import re
from urllib import urlopen
import math
def getLatRad(latitude):
return float(latitude) * (math.pi/180.0)
def getLongRad(longitude):
return float(longitude) * (math.pi/180.0)
tuplist =[]
finaltuplist = []
#start_latitude = float(input('Pls enter the latitude co-ordinate of your starting location:'))
#start_longitude = float(input('Pls enter the longitude co-ordinate of your starting location:'))
start_latitude = 41.721194054071
start_longitude = -73.934258235003
longRad1= getLongRad(start_longitude)
latRad1 = getLatRad(start_latitude)
def main():
eventids = [
'264100516989470',
'129843580476568',
'158475914271199',
]
for event in eventids:
f = urlopen('http://graph.facebook.com/%s' % event)
d = json.load(f)
name = d['name']
longitude = d["venue"]["longitude"]
latitude = d["venue"]["latitude"]
tuplist.append((name,longitude,latitude))
for coordinates in tuplist:
longRad2= getLongRad(coordinates[1])
latRad2= getLatRad(coordinates[2])
dlon = longRad2 - longRad1
dlat = latRad2 - latRad1
a = math.sin(dlat/2)**2 + math.cos(latRad1) * math.cos(latRad2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
m = 3960 * c
sum = m + m
print sum
if __name__ == '__main__':
main()
これは私が自分で行う方法を知っている限りです。開始位置からの個々の距離ではなく、往復の合計距離を取得するために誰かが私を正しい方向に向けることができる可能性はありますか?