Add home_range to device tracker

This commit is contained in:
Paulus Schoutsen committed 2015-09-20 09:35:03 -07:00
1 parent 68286dcef8
commit 19d40612e6
4 files changed
+77 -19

No files matched your search

+20
View File
@@ -1,5 +1,6 @@
"""Module with location helpers."""
import collections
from math import radians, cos, sin, asin, sqrt
import requests
@@ -28,3 +29,22 @@ def detect_location_info():
'BS', 'BZ', 'KY', 'PW', 'US', 'AS', 'VI')
return LocationInfo(**data)
# From: http://stackoverflow.com/a/4913653/646416
def distance(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance in meters between two points specified
in decimal degrees on the earth using the Haversine algorithm.
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
# Radius of earth in meters.
radius = 6371000
return c * radius