Add geofencing to automation
This commit is contained in:
1 parent
5ad27d8cdb
commit
2eb36c18bd
5 files changed
+277
-15
No files matched your search
@@ -1,8 +1,8 @@
|
||||
"""Module with location helpers."""
|
||||
import collections
|
||||
from math import radians, cos, sin, asin, sqrt
|
||||
|
||||
import requests
|
||||
from vincenty import vincenty
|
||||
|
||||
|
||||
LocationInfo = collections.namedtuple(
|
||||
@@ -31,18 +31,6 @@ def detect_location_info():
|
||||
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 = (radians(val) for val in (lon1, lat1, lon2, lat2))
|
||||
|
||||
dlon = lon2 - lon1
|
||||
dlat = lat2 - lat1
|
||||
angle = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
|
||||
# Radius of earth in meters.
|
||||
radius = 6371000
|
||||
return 2 * radius * asin(sqrt(angle))
|
||||
""" Calculate the distance in meters between two points. """
|
||||
return vincenty((lon1, lat1), (lon2, lat2)) * 1000
|
||||
Reference in new issue
Block a user