Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. ##Longitude and Latitude things.
  2. ##Harry Decamp
  3. ##8/10/2011
  4. import math
  5.  
  6. def DistanceCalculator(long1, lat1, long2, lat2):
  7.     lat1 = math.radians(lat1)
  8.     lat2 = math.radians(lat2)
  9.     long1 = math.radians(long1)
  10.     long2 = math.radians(long2)
  11.     if abs(long1) > abs(long2):
  12.         difflong = abs(long1) - abs(long2)
  13.     else:
  14.         difflong = abs(long2) - abs(long1)
  15.  
  16.     if abs(lat1) > abs(lat2):
  17.         difflat = abs(lat1) - abs(lat2)
  18.     else:
  19.         difflat = abs(lat2) - abs(lat1)
  20.  
  21.     #Haversine Formula for working out the distance between 2 points
  22.     first = math.sin(difflat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(difflong / 2) ** 2
  23.     second = 2 * math.atan2(math.sqrt(first), math.sqrt(1 - first))
  24.     radiusw = 6378
  25.     distance = radiusw * second
  26.     print "Aproximatly " + str(distance) + " Kilometers."
  27.        
  28.  
  29.  
  30.  
  31. print "---------------------"
  32. long1 = input("Current Longitude: ")
  33. lat1 = input("Current Latitude: ")
  34. print "---------------------"
  35. long2 = input("Destination Longitude: ")
  36. lat2 = input("Destination Latitude: ")
  37. print "---------------------"
  38.  
  39.  
  40. DistanceCalculator(long1, lat1, long2, lat2)
Add Comment
Please, Sign In to add comment