Hello,
Question, does someone have an example calculation to calculate the distance between 2 GPS coordinates in Lua so when the result is for example lower then 20km I can trigger an notification.
Regards
GPS calculation
Moderator: leecollings
- phoenixblue
- Posts: 76
- Joined: Friday 25 November 2016 11:20
- Target OS: Windows
- Domoticz version:
- Contact:
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: GPS calculation
a siple search on google found this:
a deeper search (the second link
) found this: https://coronalabs.com/blog/2015/01/06/ ... ap-points/
Code: Select all
local function geo_distance(lat1, lon1, lat2, lon2)
if lat1 == nil or lon1 == nil or lat2 == nil or lon2 == nil then
return nil
end
local dlat = math.rad(lat2-lat1)
local dlon = math.rad(lon2-lon1)
local sin_dlat = math.sin(dlat/2)
local sin_dlon = math.sin(dlon/2)
local a = sin_dlat * sin_dlat + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * sin_dlon * sin_dlon
local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
local d = 6378 * c
return d
endThe most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
- phoenixblue
- Posts: 76
- Joined: Friday 25 November 2016 11:20
- Target OS: Windows
- Domoticz version:
- Contact:
Re: GPS calculation
Thanks for the tip 
Sometimes it's also handy to check something else besides the forum.
Thanks.
Sometimes it's also handy to check something else besides the forum.
Thanks.