我正在尝试使用 python() 制作实时 GPS 跟踪设备。
特征
我有 10 个固定位置
loc0 = (lat0,lon0)
loc1 = (lat1,lon1)
loc2 = (lat2,lon2)
loc3 = (lat3,lon3)
loc4 = (lat4,lon4)
loc5 = (lat5,lon5)
loc6 = (lat6,lon6)
loc7 = (lat7,lon7)
loc8 = (lat8,lon8)
loc9 = (lat9,lon9)
我现在的位置
locCurrent = (latCurrent,lonCurrent)
计算距离的代码
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# 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))
km = 6367 * c
return km
怀疑
1.)当距离小于 5 公里时,我应该如何有效地触发功能,例如发送电子邮件或短信(一种可能的方法是运行无限循环并检查距离(此处为 5 公里) ,但这不是很有效,)
2.)这是除了python之外最喜欢的语言来完成同样的事情
请建议一些有关相同的文档教程,在此先感谢