Working with latitude,longitude co-ordinates

Calculated Properties' ability to work with time, to reach back to previous values, and to act conditionally, makes them very powerful for turning data into information

Converting change in lat/lon to distance moved

Why on Earth would you want to use trigonometry in Calculated Properties? Because it can turn four quite obscure numbers into something much more meaningful and useful for subsequent analysis:

distance_in_metres:

acos(

sin(latitude * 3.1415 / 180) * sin($previous/latitude * 3.141592 / 180) +
cos(latitude * 3.141592 / 180) * cos($previous/latitude * 3.141592 / 180) *
cos($previous/longitude * 3.141592 / 180 - longitude * 3.141592 / 180)

) * 6371000

This uses the Haversine formula to estimate the distance in metres that a device has moved since its last update, based on the change in lat/lon co-ordinates.

Inferring location from gateway

In some types of network most individual edge devices don't have a way to detect their own location such as a GPS receiver. But the gateways which connect them back to the internet do have GPS. Because each edge device inherits the properties of its gateway, we can look them up - in the case of The Things Network TTN LoRAWAN LPWAN this is in a metadata field:

calculated_latitude

latitude ? latitude : "{metadata.gateway.latitude}"

calculated_longitude

longitude ? longitude : "{metadata.gateway.longitude}"

So here we take the position of a device to be its own (lat,lon) if it knows it, otherwise we use its gateway's. To make this work, in your Map widget settings you must change the properties from the default latitude/longitude to calculated_latitude/calculated_longitude.

Learn more about Calculated Properties