bobross wrote:Hmmzz the scripts seems to work. In my log and position devices I get the location but.....
2016-09-15 16:05:04.880 LUA: iPhone xxxxxx: 6074.79 km from home
2016-09-15 16:05:08.934 LUA: iPhone xxxxxx: 6073.64 km from home
...i'm a long way from home.....that's strange because I'm at home right nog.
Long/Latitude are correct, timezone is Amsterdam, I didn't change the script otherwise.
What's wrong ?
That's strange, especially if the lat and lon are correct. The distance is calculated using this formula (please check if it is correctly copied into your script):
Code: Select all
distance = math.sqrt(((lon - homelongitude) * 111.320 * math.cos(math.rad(lat)))^2 + ((lat - homelatitude) * 110.547)^2)
In other words: one degree is apprximately 110.547 km for latitude, and approximately 111.32 km times cos(lat) for longitude. Then I'm just using Pythagoras for the distance (a^2 + b^2 = c^2).
You say "long/latitude are correct". Do you mean of your house, or did you add print commands (e.g. print(lat .. ' ' .. lon')) to check if it reports your actual correct position? You're saying it does give the right address in the text devices? Is the distance between the brackets correct?
Raspberry Pi 2B - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 based water meter - Logitech Media Server - Kodi - Wall mounted tablet + Imperihome - MANY switches/sensors