GPS Marker according to geofencing

#1

Hi, I’m just starting to use the platform and its pretty amazing. I need help for something though.

I would like to have the marker on a GPS History block red if the device is outside a defined area and green otherwise. How could I do this? I thought of doing the calculation in a workflow and updating a attribute or a tag, but how could I access this info from the GPS block?

Thanks!

#2

There are a couple different ways you could do this, but probably the easiest (if you are just using a simple circular area) is to use a template for the gps pin and in the template use the gpsDistance format helper. This way you can calculate the distance between the center of your area and the current point - and have the pin template set a different color depending on how large the distance is.

For example:

{{#lte  (gpsDistance data.location "34.125029, -84.519125")  5000 }}
{{colorMarker '#8db319'}}
{{else}}
{{colorMarker '#ff261b'}}
{{/lte}}

If the gps attribute is data.location, then when that coordinate is within 5000 meters of “34.125029, -84.519125” the marker will be ‘#8db319’, otherwise it will be ‘#ff261b’.

Hope that helps!

#3

Wow, thank you for the super fast response, it works nicely.

Now the thing is that I’m trying to make it dynamic and the center point would change from device to device. I am thinking of having the coordinates as a tag, but how can I pull the tags from the block? I’m trying to do {{ deviceTags.[origin] }} but it doesn’t work.

More generally, I think it would be ideal to set a tag from a workflow according to whatever logic and just reading this tag from the GPS block. I’m picturing having several devices on a map and having the marker change depending on the state of the device (low bat, door open, outside area, etc). Or, am I missing something? I guess it would be possible right on the block if all variables are reported together, but what if its not the case or if the logic includes something external to the device.

#4

You probably need to do deviceTags.origin.[0] (assuming origin is the tag name). Since we allow the same key to be used multiple times as a tag key, when presented in object key-value form, the values are always an array (even though the common case is just the single value).

And yes, you can totally do what you are talking about in a workflow - you can, for instance, use the geofence node and the device state node to add a value for a “calculated” state attribute based off of the reported gps location (and it will be attached to the same timestamp as the gps location report).