Evaluate device positions against geofences - Amazon Location Service

Evaluate device positions against geofences

There are two ways to evaluate positions against geofences to generate geofence events:

  • You can link Trackers and Geofence Collections. For more information, see the section: Link a tracker to a geofence collection.

  • You can make a direct request to the geofence collection resource to evaluate one or more positions.

If you also want to track your device location history or display locations on a map, link the tracker with a geofence collection. Alternatively, you may not want to evaluate all location updates, or you don't intend to store location data in a tracker resource If either of these is the case, you can make a direct request to the geofence collection and evaluate one or more device positions against its geofences.

Evaluating device positions against geofences generates events. You can react to these events and route them to other AWS services. For more information about actions that you can take when receiving geofence events, see Reacting to Amazon Location Service events with Amazon EventBridge.

The following examples use the AWS CLI, or the Amazon Location APIs.

API

To evaluate device positions against the position of geofences using the Amazon Location APIs

Use the BatchEvaluateGeofences operation from the Amazon Location Geofences APIs.

The following example uses an API request to evaluate the position of device ExampleDevice to an associated geofence collection ExampleGeofenceCollection.

POST /geofencing/v0/collections/ExampleGeofenceCollection/positions HTTP/1.1 Content-type: application/json { "DevicePositionUpdates": [ { "DeviceId": "ExampleDevice", "Position": [-123.17805, 49.19284], "SampleTime": "2020-10-02T19:09:07.327Z" } ] }
AWS CLI

To evaluate device positions against the position of geofences using AWS CLI commands

Use the batch-evaluate-geofences command.

The following example uses an AWS CLI to evaluate the position of ExampleDevice-1 and ExampleDevice-2 against an associated geofence collection ExampleGeofenceCollection.

aws location \ batch-evaluate-geofences \ --collection-name ExampleGeofenceCollection \ --device-position-updates "DeviceId=ExampleDevice-1,Position=-123.123,47.123,SampleTime=2020-11-10T12:45:34.123Z" "DeviceId=ExampleDevice-2,Position=-123.123,47.123,SampleTime=2020-11-10T12:45:34.123Z"