amazon-web-servicesgeospatialamazon-location-service

How to look up Geofence based on location coordinates with Amazon Locations Service?


I'm evaluating tools for geospatial storage and came across Amazon Location Service. The API docs show that there are operations for creating and managing Geofence objects. However, I don't see any API for searching Geofence(s) based on X,Y location coordinates. Am I missing some key semantics or is this not an intended use case for Amazon Location Service?

Edit: to help clarify, I'm looking for an API that takes as input the latitude/longitude of a location as input and returns the Geofences in which those coordinates fall (if any).


Solution

  • Amazon Location Service doesn't provide a direct API to synchronously query geofences containing specific coordinates. Instead, the intended approach is to use BatchEvaluateGeoFences, which asynchronously checks coordinates against geofences and triggers Amazon EventBridge events (like ENTER or EXIT) when breaches occur. You can then process these events (e.g., with AWS Lambda) to determine which geofences contain the coordinates.

    Here's an example CLI command to evaluate a devices coordinates.

    aws location batch-evaluate-geofences \
        --collection-name "YourGeofenceCollection" \
        --device-positions '[{"DeviceId": "device1", "Position": [-123.115, 49.282], "SampleTime": "2025-05-23T00:00:00Z"}]'
    

    You can then configure an EventBridge rule, and trigger, to catch and process these events.