Calculate the great circle distance between two points on the earth (specified in decimal degrees)
(lat1, lon1, lat2, lon2)
| 88 | |
| 89 | # calculte the distance between two points |
| 90 | def distance(lat1, lon1, lat2, lon2): |
| 91 | """ |
| 92 | Calculate the great circle distance between two points |
| 93 | on the earth (specified in decimal degrees) |
| 94 | """ |
| 95 | # convert decimal degrees to radians |
| 96 | lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) |
| 97 | # haversine formula |
| 98 | dlon = lon2 - lon1 |
| 99 | dlat = lat2 - lat1 |
| 100 | a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 |
| 101 | c = 2 * asin(sqrt(a)) |
| 102 | r = 6371 # Radius of earth in kilometers. Use 3956 for miles |
| 103 | return c * r * 1000 |
nothing calls this directly
no outgoing calls
no test coverage detected