title: Calculating distance between latitude and longitude in python?
body: <p>I need help calculating the distance between two points-- in this case, the two points are longitude and latitude. I have a .txt file that contains longitude and latitude in columns like this: </p>
  
  <pre><code>-116.148000 32.585000
  -116.154000 32.587000
  -116.159000 32.584000
  </code></pre>
  
  <p>The columns do not have headers. I have many more latitudes and longitudes.</p>
  
  <p>So far, i have come up with this code: </p>
  
  <pre><code>from math import sin, cos, sqrt, atan2, radians
  R = 6370
  lat1 = radians()  #insert value
  lon1 = radians()
  lat2 = radians()
  lon2 = radians()
  
  dlon = lon2 - lon1
  dlat = lat2- lat1
  
  a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
  c = 2 * atan2(sqrt(a), sqrt(1-a))
  distance = R * c
  print (distance)
  </code></pre>
  
  <p>Many of the answers/code i've seen on stack overflow for calculating the distance between longitude and latitude have had longitude and latitude assigned as specific values. </p>
  
  <p>I would like the longitude and latitude to equal the values in the columns they are in and for the equation to go through all of the longitudes and latitudes and calculate the distance.</p>
  
  <p>I have not been able to come up with something to do this. Any help would be appreciated</p>