Geofences and Trackers - Amazon Location Service

Geofences and Trackers

This section provides and overview of the concepts of working with Amazon Location Service geofences and trackers. Geofences are polygon boundaries that you can use to be notified when devices or positions move in and out of the areas. Tracker resources are used to store and update positions for devices as they move.

Note

For information about how to use geofences and trackers in practice, see Geofencing an area of interest using Amazon Location.

Geofences

Geofence collection resources allow you to store and manage geofences—virtual boundaries on a map. You can evaluate locations against a geofence collection resource and get notifications when the location update crosses the boundary of any of the geofences in the geofence collection.

The following shows you how to create and use geofence collection resources:

  1. Create a geofence collection resource in your AWS account.

  2. Add geofences to that collection. You can do so by either using the geofence upload tool on the Amazon Location console, or by using the Amazon Location Geofences API. For more information about available options, see Accessing Amazon Location.

    Geofences can either be defined by a polygon or by a circle. Use a polygon to find when a device enters a specific area. Use a circle to find when a device comes within a certain distance (radius) of a point.

  3. You can start evaluating locations against all your geofences. When a location update crosses the boundaries of one or more geofences, your geofence collection resource emits one of the following geofence event types on Amazon EventBridge:

    • ENTER – One event is generated for each geofence where the location update crosses its boundary by entering it.

    • EXIT – One event is generated for each geofence where the location update crosses its boundary by exiting it.

    For more information, see Reacting to Amazon Location Service events with Amazon EventBridge. You can also integrate monitoring using services such as Amazon CloudWatch and AWS CloudTrail. For more information see, Monitoring Amazon Location Service with Amazon CloudWatch and Logging and monitoring with AWS CloudTrail.

For example, if you are tracking a fleet of trucks, and you want to get notified when a truck comes within a certain area of any of your warehouses. You can create a geofence for the area around each warehouse. Then, when the trucks send you updated locations, you can use Amazon Location Service to evaluate those positions and see if a truck has entered (or exited) one of the geofence areas.

Note

Your are billed by the number of geofence collections you evaluate against. Your bill is not affected by the number of geofences in each collection. Since each geofence collection may contain up to 50,000 geofences, you may want to combine your geofences into fewer collections, where possible, to reduce your cost of geofence evaluations. The events generated will include the ID of the individual geofence in the collection, as well as the ID of the collection.

Geofence events

Locations for positions you are monitoring are referenced by an ID called a DeviceId (and the positions are referred to as device positions). You can send a list of device positions to evaluate directly to the geofence collection resource, or you can use a tracker. See the next section for more information on trackers.

You receive events (via Amazon EventBridge) only when a device enters or exits a geofence, not for every position change. This means that you will typically receive events and have to respond to them much less frequently than every device position update.

Note

For the first location evaluation for a specific DeviceID, it is assumed that the device was previously not in any geofences. So the first update will generate an ENTER event, if inside a geofence in the collection, and no event if not.

In order to calculate whether a device has entered or exited a geofence, Amazon Location Service must keep previous position state for the device. This position state is stored for 30 days. After 30 days without an update for a device, a new location update will be treated as the first position update.

Trackers

A tracker stores position updates for a collection of devices. The tracker can be used to query the devices' current location or location history. It stores the updates, but reduces storage space and visual noise by filtering the locations before storing them.

Each position update stored in your tracker resources can include a measure of position accuracy and up to 3 fields of metadata about the position or device that you want to store. The metadata is stored as key-value pairs, and can store information such as speed, direction, tire pressure, or engine temperature.

Note

Tracker storage is encrypted with AWS owned keys automatically. You can add another layer of encryption using KMS keys that you manage, to ensure that only you can access your data. For more information, see Data encryption at rest for Amazon Location Service.

Tracker position filtering and storage are useful on their own, but trackers are especially useful when paired with geofences. You can link trackers to one or more of your geofence collection resources, and position updates are evaluated automatically against the geofences in those collections. Proper use of filtering can greatly reduce the costs of your geofence evaluations, as well.

The following diagram shows you how to create and use tracker resources:

  1. First, you create a tracker resource in your AWS account.

  2. Next, decide how you send location updates to your tracker resources. The Android and iOS SDKs offer integrated tracking capabilities for your mobile applications. Alternately, you can use MQTT by following step-by-step directions in tracking using MQTT in this guide.

  3. You can now use your tracker resource to record location history and visualize it on a map.

  4. You can also link your tracker resource to one or more geofence collections so that every position update sent to your tracker resource is automatically evaluated against all the geofence in all the linked geofence collections. You can link resource on the tracker resource details page of the Amazon Location console or by using the Amazon Location Trackers API.

  5. You can then integrate monitoring using services such as Amazon CloudWatch and AWS CloudTrail. For more information see, Monitoring Amazon Location Service with Amazon CloudWatch and Logging and monitoring with AWS CloudTrail.

Using trackers with geofences

Trackers provide additional functionality when paired with geofences. You associate a tracker with a geofence collection, either through the Amazon Location console or the API, to automatically evaluate tracker locations. Each time the tracker receives an updated location, that location will be evaluated against each geofence in the collection, and the appropriate ENTER and EXIT events are generated in Amazon EventBridge. You can also apply filtering to the tracker, and, depending on the filtering, you can reduce the costs for geofence evaluations by only evaluating meaningful location updates.

If you associate the tracker with a geofence collection after it has already received some position updates, the first position update after association is treated as an initial update for the geofence evaluations. If it is within a geofence, you will receive an ENTER event. If it is not within any geofences you will not receive an EXIT event, regardless of the previous state.

Position filtering

Trackers can automatically filter the positions that are sent to them. There are several reasons why you might want to filter out some of your device location updates. If you have a system that only sends reports every minute or so, you might want to filter devices by time, storing and evaluating positions only every 30 seconds. Even if you are monitoring more frequently, you might want to filter position updates to clean up the noisiness of GPS hardware. GPS position locations are inherently noisy. Their accuracy is not 100% perfect, so even a device that is stationary appears to be moving around slightly. At low speeds, this jitter causes visual clutter and can cause false entry and exit events if the device is near the edge of a geofence.

The position filtering works as position updates are received by a tracker, reducing visual noise in your device paths (jitter), reducing the number of false geofence entry and exit events, and helping manage costs by reducing the number of position updates stored and geofence evaluations triggered.

Trackers offer three position filtering options to help manage costs and reduce jitter in your location updates.

  • Accuracy-basedUse with any device that provides an accuracy measurement. Most GPS and mobile devices provide this information. The accuracy of each position measurement is affected by many environmental factors, including GPS satellite reception, landscape, and the proximity of wifi and bluetooth devices. Most devices, including most mobile devices, can provide an estimate of the accuracy of the measurement along with the measurement. With AccuracyBased filtering, Amazon Location ignores location updates if the device moved less than the measured accuracy. For example, if two consecutive updates from a device have an accuracy range of 5 m and 10 m, Amazon Location ignores the second update if the device has moved less than 15 m. Amazon Location neither evaluates ignored updates against geofences, nor stores them.

    When accuracy is not provided, it is treated as zero, and the measurement is considered perfectly accurate, and no filtering will be applied to the updates.

    Note

    You can use accuracy-based filtering to remove all filtering. If you select accuracy-based filtering, but override all accuracy data to zero, or omit the accuracy entirely, then Amazon Location will not filter out any updates.

    In most scenarios, accuracy-based filtering is a good choice for filtering position updates, providing a balance of tracking location while filtering out unneeded updates, thereby reducing costs.

  • Distance-basedUse when your devices do not provide an accuracy measurement, but you still want to take advantage of filtering to reduce jitter and manage costs. DistanceBased filtering ignores location updates in which devices have moved less than 30 m (98.4 ft). When you use DistanceBased position filtering, Amazon Location neither evaluates these ignored updates against geofences nor stores the updates.

    The accuracy of most mobile devices, including the average accuracy of iOS and Android devices, is within 15 m. In most applications, DistanceBased filtering can reduce the effect of location inaccuracies when displaying device trajectory on a map, and the bouncing effect of multiple consecutive entry and exit events when devices are near the border of a geofence. It can also help reduce the cost of your application, by making fewer calls to evaluate against linked geofences or retrieve device positions.

    Distance-based filtering is useful if you want to filter, but your device doesn't provide accuracy measurements, or you want to filter out a larger number of updates than with accuracy-based.

  • Time-based – (default) Use when your devices send position updates very frequently (more than once every 30 seconds), and you want to achieve near real-time geofence evaluations without storing every update. In TimeBased filtering, every location update is evaluated against linked geofence collections, but not every location update is stored. If your update frequency is more often than 30 seconds, only one update per 30 seconds is stored for each unique device ID.

    Time-based filtering is particularly useful when you want to store fewer positions, but want every position update to be evaluated against the associated geofence collections.

Note

Be mindful of the costs of your tracking application when deciding your filtering method and the frequency of position updates. You are billed for every location update and once for evaluating the position update against each linked geofence collection. For example, when using time-based filtering, if your tracker is linked to two geofence collections, every position update will count as one location update request and two geofence collection evaluations. If you are reporting position updates every 5 seconds for your devices and using time-based filtering, you will be billed for 720 location updates and 1,440 geofence evaluations per hour for each device.

Geofence terminology

Geofence Collection

Contains zero or more geofences. It is capable of geofence monitoring by emitting Entry and Exit events, when requested, to evaluate a device position against its geofences.

Geofence

A polygon or circle geometry that defines a virtual boundary on a map.

Polygon geometry

An Amazon Location geofence is a virtual boundary for a geographical area and is represented as a polygon geometry or as a circle.

A circle is a point with a distance around it. Use a circle when you want to be notified if a device is within a certain distance of a location.

A polygon is an array composed of 1 or more linear rings. Use a polygon when you want to define a specific boundary for device notifications. A linear ring is an array of four or more vertices, where the first and last vertex are the same to form a closed boundary. Each vertex is a 2-dimensional point of the form [longitude, latitude], where the units of longitude and latitude are degrees. The vertices must be listed in counter-clockwise order around the polygon.

Note

Amazon Location Service doesn't support polygons with more than one ring. This includes holes, islands or multipolygons. Amazon Location also doesn't support polygons that are wound clockwise, or that cross the antimeridian.

The following is an example of a single linear external ring:

[ [ [-5.716667, -15.933333], [-14.416667, -7.933333], [-12.316667, -37.066667], [-5.716667, -15.933333] ] ]

Tracker terminology

Tracker resource

An AWS resource that receives location updates from devices. The tracker resource provides support for location queries, such as current and historic device location. Linking a tracker resource to a geofence collection evaluates location updates against all geofences in the linked geofence collection automatically.

Position data tracked

A tracker resource stores information about your devices over time. The information includes a series of position updates, where each update includes location, time, and optional metadata. The metadata can include a position's accuracy, and up to three key-value pairs to help you track key information about each position, such as speed, direction, tire pressure, remaining fuel, or engine temperature of the vehicle you are tracking. Trackers maintain device location history for 30 days.

Position filtering

Position filtering can help you control costs and improve the quality of your tracking application by filtering out position updates that don't provide valuable information before the updates are stored or evaluated against geofences.

You can choose AccuracyBased, DistanceBased, or TimeBased filtering. By default, position filtering is set to TimeBased.

You can configure position filtering when you create or update tracker resources.

RFC 3339 timestamp format

Amazon Location Service Trackers uses the RFC 3339 format, which follows the International Organization for Standardization (ISO) 8601 format for dates and time.

The format is “YYYY-MM-DDThh:mm:ss.sssZ+00:00”:

  • YYYY-MM-DD — Represents the date format.

  • T — Indicates that the time values will follow.

  • hh:mm:ss.sss — Represents the time in 24-hour format.

  • Z — Indicates that the time zone used is UTC, which can be followed with deviations from the UTC time zone.

  • +00:00 — Optionally indicate deviations from the UTC time zone. For example, +01:00 indicates UTC + 1 hour.

Example

For July 2, 2020, at 12:15:20 in the afternoon, with an adjustment of an additional 1 hour to the UTC time zone.

2020-07-02T12:15:20.000Z+01:00