Process data in the cloud

Create a geofence

Geofences can be circular (specified by a centre point and a radius) or polygonal (an array of coordinates).

curl -X POST \
  'https://tracking.api.here.com/geofences/v2' \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json' \
  -d '{
  "type": "circle",
  "definition":  {
    "center": {
      "lat": 52.521749,
      "lng": 13.413175
    },
    "radius": 150
  }
}'

This will create a circular geofence and return the unique ID. At this point, the geofence isn't associated with any device but it will be visible on the web dashboard.

You can also get a list of geofences you previously created. If you are a member of multiple projects, please specify the Project ID in projectId query parameter.

curl -X GET \
  'https://tracking.api.here.com/geofences/v2' \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

Associate geofence and device

Now that we have a device sending its location and a geofence around an area, we can associate one to the other. This will cause a notification to be sent whenever this device transitions from outside-the-geofence to inside-the-geofence or vice versa.

curl -X PUT \
  https://tracking.api.here.com/associations/v3/{trackingId}/geofences/{geofenceId} \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

Send telemetry outside the geofence then inside the geofence. Note that timestamps are in milliseconds since Epoch timestamp.

curl -X POST \
  https://tracking.api.here.com/v2/ \
  -H 'authorization: Bearer {deviceToken}' \
  -H 'content-type: application/json' \
  -d '[{
      "timestamp": 1569300623000,
      "position": {
        "alt": 107,
        "accuracy": 13,
        "lat": 52.520806,
        "lng": 13.410514,
        "altaccuracy": 14
      }
}]'
curl -X POST \
  https://tracking.api.here.com/v2/ \
  -H 'authorization: Bearer {deviceToken}' \
  -H 'content-type: application/json' \
  -d '[{
      "timestamp": 1569300814000,
      "position": {
        "alt": 107,
        "accuracy": 10,
        "lat": 52.521880,
        "lng": 13.412724,
        "altaccuracy": 15
      }
}]'

You can confirm the location of the updates using the web dashboard. The scenario created here will look like

See a transition was recorded

All geofence transitions are recorded in the event log.

curl -X GET \
  https://tracking.api.here.com/events/v3/{trackingId} \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

results matching ""

    No results matching ""