A geofence is a virtual fence. Instead of posts and wire, it is a boundary drawn on a map, and instead of keeping things in or out physically, it watches for things crossing it and reacts. When a delivery van enters a customer's street, a parcel app marks the order "arriving now." When an employee's phone leaves a job site, a timesheet stops the clock. When an autonomous drone drifts toward restricted airspace, a flight controller pulls it back. All three are geofences doing the same job: turning a location into an event.
This guide explains what a geofence actually is, how the underlying test works, and how to build location-aware behaviour into an app or an AI agent.
The Core Idea in 30 Seconds
A geofence has two parts: a shape and a rule.
The shape is a region on the Earth's surface. The two common forms are a circle, defined by a centre coordinate and a radius in metres, and a polygon, defined by an ordered list of latitude and longitude points that trace an outline. A circle is enough for "within 200 metres of this shop." A polygon is what you need for "inside this delivery zone" or "within these city limits," where the boundary is irregular.
The rule is what happens when something crosses the shape. The two events that matter are enter (a tracked entity moves from outside to inside) and exit (inside to outside). Some systems add a third, dwell, which fires when an entity stays inside for longer than a set time.
That is the whole concept. Everything else is engineering detail around accuracy, performance, and reliability.
How the Test Actually Works
At each position update, the system runs a containment test: is this coordinate inside this shape or not?
For a circle, the test is a distance calculation. Measure the great-circle distance from the device to the centre point; if it is less than the radius, the device is inside. For a polygon, the standard method is the point-in-polygon ray-casting test: draw an imaginary line from the point off to infinity and count how many times it crosses the polygon's edges. An odd number of crossings means the point is inside; an even number means outside.
The geometry is cheap. A modern device can run thousands of these tests per second. The hard parts are everything around it:
- Accuracy. GPS drifts. A phone sitting still can report positions that wander by tens of metres, which causes phantom enter and exit events near a boundary. Production geofencing adds hysteresis (requiring the device to cross a little past the line before firing) and confidence thresholds.
- Battery. Polling GPS constantly drains a phone. Mobile operating systems provide low-power geofencing APIs that use Wi-Fi and cell signals to wake the app only when a boundary is likely being crossed.
- State. An enter event only makes sense if you know the previous state was outside. The engine has to remember each entity's last-known relationship to each geofence.
Where the Coordinates Come From
A geofence check is only as good as the coordinate you feed it. That coordinate has to come from somewhere, and it is rarely already in clean latitude and longitude form.
In the real world you usually start with an address ("Hauptstrasse 12, Berlin"), a place name ("the central warehouse"), or a raw signal. Turning those into the precise [lng, lat] a geofence test needs is the job of geocoding and reverse geocoding:
- Geocoding converts an address or place name into coordinates, so you can build a geofence around a customer's location or check whether an order's destination falls inside a delivery zone.
- Reverse geocoding converts coordinates back into a human-readable address, so an enter event can say "arrived at 12 Hauptstrasse" instead of "arrived at 52.5200, 13.4050."
- Place data lets you anchor geofences to known points of interest rather than hand-drawn shapes.
This is where a location-data platform does the heavy lifting. MapAtlas provides GDPR-compliant geocoding, reverse geocoding, and place search across Europe and beyond, so the coordinate going into your point-in-polygon test is accurate and the event coming out is meaningful.
Geofencing for AI Agents
Geofencing used to be a mobile-app feature. In 2026 it is increasingly something AI agents reason about. An agent handling logistics, field service, or travel needs to answer questions like "is this driver inside the depot zone yet?" or "which of these stores is within the customer's 15-minute reach?"
For that, the agent needs two things: clean location data and a boundary to test against. It can pull a coordinate through a geocoding API, define or load a geofence as a GeoJSON polygon, and run the containment check as a tool call. Pair geofencing with an isochrone (a travel-time boundary rather than a fixed shape) and the agent can reason about reachability, not just raw distance, which is far closer to how people actually think about "nearby."
Common Use Cases
- Delivery and logistics. Trigger "out for delivery" and "arrived" events; alert when a vehicle leaves its planned corridor.
- Field service and workforce. Automatic check-in and check-out when staff enter or leave a job site.
- Retail and marketing. Send a relevant message when a known user is near a store, with consent.
- Fleet and asset tracking. Get an alert the moment equipment leaves an authorised area.
- Safety and compliance. Warn when a device enters a hazard zone or restricted airspace.
Building It Right
A reliable geofence comes down to three things: store your boundaries cleanly (GeoJSON is the de facto standard), source accurate coordinates (a good geocoding and reverse-geocoding API matters more than the geometry code), and design for the messy edge cases (GPS drift, lost signal, and devices that sit exactly on the line).
Get those right and a geofence becomes one of the most reliable ways to connect the physical world to your software, whether the thing crossing the boundary is a delivery van, a phone, or an AI agent reasoning about where things are.
Related Reading
Frequently Asked Questions
What is a geofence?
A geofence is a virtual boundary drawn around a real-world geographic area. When a device, vehicle, or software agent crosses that boundary, the system fires an event: a notification, a database update, a webhook, or any other action. The boundary can be a simple circle (a centre point plus a radius) or an arbitrary polygon traced around a building, a delivery zone, a city district, or a hazard area. Geofencing is one of the core building blocks of location-based services.
How does geofencing work?
Geofencing works by continuously comparing a device's current position against one or more stored boundary shapes. A location source (GPS, Wi-Fi, cell, or IP) reports coordinates; a point-in-polygon or point-in-radius test decides whether those coordinates fall inside or outside each geofence; and a state change from outside to inside (or inside to outside) triggers an enter or exit event. The test itself is fast geometry, so the engineering challenge is usually accuracy, battery use, and avoiding false triggers near the edge.
What is the difference between a geofence and a geofence warrant?
A geofence in software engineering is a virtual boundary you define to trigger app behaviour, such as a delivery alert or a check-in. A geofence warrant is a legal request that asks a data holder to reveal which devices were inside a geographic area during a time window. They share the same underlying concept, a boundary on a map, but one is a product feature you build and the other is a law-enforcement instrument. This article is about the engineering kind.
Do I need GPS to use geofencing?
Not always. GPS gives the most precise position outdoors, but geofences can also be evaluated against coarser location sources such as Wi-Fi, cell-tower triangulation, or IP-based geolocation when precision is less critical. The right source depends on the size of your geofence: a 50-metre boundary around a shop entrance needs GPS-grade accuracy, while a city-wide or country-wide zone works fine with coarse location.
How do I add geofencing to my app or AI agent?
Store your boundaries as GeoJSON polygons or circles, get a reliable coordinate for the entity you are tracking (often via a geocoding or reverse-geocoding API), and run a point-in-polygon test on each position update. MapAtlas provides the geocoding, reverse geocoding, and place data that turn a street address or a place name into the precise coordinates a geofence check needs, so an AI agent can reason about whether a user, asset, or order is inside a given zone.

