geofenceTemplate property
Optional custom template for rendering geofence
JSON request data in HTTP requests.
The geofenceTemplate
is similar to locationTemplate with the addition of two extra geofence.*
tags.
The geofenceTemplate
will be evaluated for variables using Ruby erb
-style tags:
<%= variable_name %>
See also:
BackgroundGeolocation.ready(Config(
geofenceTemplate: '{ "lat":<%= latitude %>, "lng":<%= longitude %>, "geofence":"<%= geofence.identifier %>:<%= geofence.action %>" }'
));
// Or use a compact [Array] template!
BackgroundGeolocation.ready(Config(
geofenceTemplate: '[<%= latitude %>, <%= longitude %>, "<%= geofence.identifier %>", "<%= geofence.action %>"]'
))
Warning: quoting String
data.
The plugin does not automatically apply double-quotes around String
data. The plugin will attempt to JSON encode your template exactly as you're configured.
The following will generate an error:
BackgroundGeolocation.ready(Config(
locationTemplate: '{"timestamp": <%= timestamp %>}'
));
Since the template-tag timestamp
renders a string, the rendered String will look like this:
{"timestamp": 2018-01-01T12:01:01.123Z}
The correct locationTemplate
is:
BackgroundGeolocation.ready(Config(
locationTemplate: '{"timestamp": "<%= timestamp %>"}'
));
{"timestamp": "2018-01-01T12:01:01.123Z"}
Template Tags
The tag-list is identical to locationTemplate with the addition of geofence.identifier
and geofence.action
.
Tag | Type | Description |
---|---|---|
geofence.identifier |
String |
Which geofence? |
geofence.action |
String |
ENTER/EXIT |
latitude |
Float |
|
longitude |
Float |
|
speed |
Float |
Meters |
heading |
Float |
Degrees |
accuracy |
Float |
Meters |
altitude |
Float |
Meters |
altitude_accuracy |
Float |
Meters |
timestamp |
String |
ISO-8601 |
uuid |
String |
Unique ID |
event |
String |
motionchange,geofence,heartbeat,providerchange |
odometer |
Float |
Meters |
activity.type |
String |
still,on_foot,running,on_bicycle,in_vehicle,unknown |
activity.confidence |
Integer |
0-100% |
battery.level |
Float |
0-100% |
battery.is_charging |
Boolean |
Is device plugged in? |
mock |
Boolean |
true when geofence was recorded from a Mock location app. |
is_moving |
Boolean |
true when geofence was recorded while SDK was in moving state. |
timestampMeta |
Object |
Renders timestamp meta-data. See Config.enableTimestampMeta. |
Implementation
String? geofenceTemplate;