Library of Functions


Description


Calculates the distance between two geographical points.

Usage and Arguments


fibaro:calculateDistance(position1, position2)

  • position1: the first location
  • position2: the second location

A point is expressed by latitude and longitude. The values ​​are expressed in degrees with a decimal part and are separated by a semicolon. Negative values ​​are, respectively, west and south. The decimal separator is a dot.

For example, point 40°44’55″N, 73°59’11″W would be saved as a string “40.7486;-73.9864″.

Returned Values


Distance expressed in meters

Examples


local userLocation = fibaro:getValue(123, 'Location'); -- 123 is the ID of the user
local exampleLocation = "52.4325295140701;16.8450629997253";
 
local result;
 
result = fibaro:calculateDistance(userLocation, exampleLocation);
fibaro:debug('The distance is ' .. result .. 'm.');