# Geofence creation guide

> For the complete documentation index, see [llms.txt](https://help.1nce.com/llms.txt).

## Prerequisites

Before creating geofences, ensure that [Geofence Credits](/docs/1nce-os/1nce-os-device-locator/#geofence-credits) are available in your account. Without active credits, geofence creation is not possible.

## Creating a Geofence

To create a new geofence, click the **+ New Geofence** button on the Device Locator page.

<div style={{textAlign: 'center'}}>
![New Geofence button](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/new-geofence-button.png)

*New Geofence button*
</div>

### Scope

Select the scope for the new geofence — **Global** or **Device Specific**.

* **Global** geofences apply to all devices in your account. You can create up to 10 global geofences.
* **Device Specific** geofences are tied to a single device (identified by ICCID). You can create 1 device-specific geofence per device.

<div style={{textAlign: 'center'}}>
![Geofence scope selection](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/new-geofence-scope.png)

*Geofence scope selection*
</div>

### Name

Enter a name for the geofence.

:::info Naming convention for device-specific geofences
For device-specific geofences, you can later filter geofences either by entering the full ICCID or by searching multiple geofences by name prefix. Choosing a consistent naming convention (e.g., a shared prefix like `warehouse-` or `fleet-`) makes it easier to find and manage groups of device-specific geofences.
:::

### Type

Select the geofence shape — **Polygon** or **Circle**.

* **Polygon** — draw the geofence boundary directly on the map by placing up to 50 coordinate points.

<div style={{textAlign: 'center'}}>
![Drawing a polygon geofence on the map](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/new-geofene-polygon.png)

*Polygon geofence*
</div>

* **Circle** — draw a circle around a selected center point on the map. The radius must be between 50 m and 30,000 m.

<div style={{textAlign: 'center'}}>
![Drawing a circle geofence on the map](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/new-geofene-circle.png)

*Circle geofence*
</div>

### Event Types

Choose which crossing events should trigger a [geofence event](/docs/1nce-os/1nce-os-cloud-integrator/cloud-integrator-output-format/#geofence):

* **Enter** — triggered when a device enters the geofence boundary
* **Exit** — triggered when a device exits the geofence boundary
* **Enter & Exit** — triggered on both entry and exit

### Event Sources

Select the location data source used to evaluate geofence crossings:

* **[Cell Tower](/docs/1nce-os/1nce-os-device-locator/#cell-tower-location)** — uses cell tower-based location data
* **[GPS](/docs/1nce-os/1nce-os-device-locator/#gps-location)** — uses GPS coordinates reported by the device (via [Energy Saver](/docs/1nce-os/1nce-os-energy-saver/energy-saver-device-locator-integration/) or [LwM2M](/docs/1nce-os/1nce-os-lwm2m/lwm2m-device-locator-integration/))
* **Cell Tower & GPS** — evaluates against both sources

### ICCID (Device Specific only)

Enter the ICCID of the device. The system can automatically determine the latest device location (if available).

**Device location is available:**

When creating a device-specific geofence with the Circle type, the system retrieves the latest known device location. To use this location as the center of the circle, click the location icon next to the filled ICCID field.

<div style={{textAlign: 'center'}}>
![Device-specific geofence with known location](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/device-specific-location-known.png)

*Device location available*
</div>

**Device location is not available:**

If the device does not have a known location, the system cannot automatically determine its position. You will need to draw the geofence boundary manually on the map.

<div style={{textAlign: 'center'}}>
![Device-specific geofence with unknown location](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/device-specific-location-unknown.png)

*Device location not available*
</div>

## Viewing Geofences

Besides viewing geofences in the portal, you can also retrieve the full list programmatically via the [Get all geofences](/api/1nce-os/get-all-geofences/) API endpoint.

### Global Geofences

When the global geofences view is selected, all global geofences are loaded and shown in the dropdown list. All global geofences are also placed on the map.

<div style={{textAlign: 'center'}}>
![Viewing global geofences on the map](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/view-global-geofences.png)

*Global geofences view*
</div>

### Device Specific Geofences

When looking for device-specific geofences, you can either enter the full ICCID or use a name prefix to filter results (up to 10 geofences will be shown).

**By full ICCID:**

<div style={{textAlign: 'center'}}>
![Viewing device geofence by ICCID](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/view-device-geofence-by-iccid.png)

*Filter by full ICCID*
</div>

**By name prefix:**

<div style={{textAlign: 'center'}}>
![Viewing device geofences by name prefix](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/view-device-geofence-by-prefix.png)

*Filter by name prefix*
</div>

## Editing and Deleting Geofences

By clicking on a geofence, you can view its details and choose to **Edit** or **Delete** it.

<div style={{textAlign: 'center'}}>
![Geofence details with Edit and Delete options](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/view-geofence-details.png)

*Geofence details*
</div>

When editing a geofence, only the following fields can be changed:

* **Name**
* **Event Types**
* **Event Sources**

Coordinates and geofence type cannot be modified. To change the shape or location, delete the existing geofence and create a new one.

<div style={{textAlign: 'center'}}>
![Editing a geofence](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/edit-geofence.png)

*Edit geofence*
</div>

## Quick Test: End-to-End Validation

Ensure you have active [Geofence Credits](/docs/1nce-os/1nce-os-device-locator/#geofence-credits) before proceeding.

Follow these steps to quickly validate that your geofence setup is working correctly.

**1. Create a Cloud Integration**

Set up a [Webhook Cloud Integration](/docs/1nce-os/1nce-os-cloud-integrator/cloud-integrator-webhook-configuration/#webhook-creation) and select **Geofence** as the Event Type. A temporary webhook (e.g., using [webhook.site](https://webhook.site)) is sufficient for testing purposes.

**2. Simulate a GPS location for your device**

Use the Energy Saver [template example](/docs/1nce-os/1nce-os-energy-saver/energy-saver-device-locator-integration/#template-example) to send a GPS location from your device. This establishes the initial device position.

**3. Create a device-specific geofence using the device location**

Create a device-specific circle geofence as described in the [ICCID section](#iccid-device-specific-only). The system will use the location reported in step 2 as the center of the geofence.

**4. Simulate new GPS locations that enter and exit the geofence**

Using the same Energy Saver template example, send GPS coordinates that are inside and then outside the geofence boundary. This triggers Enter and Exit events.

**5. Validate geofence events in the Webhook**

Check your webhook endpoint for incoming geofence events. You should see **ENTER** and/or **EXIT** events depending on the simulated locations and your geofence event type configuration.

## Retrieving Geofence events

After geofence is created, [Cloud integrator](/docs/1nce-os/1nce-os-cloud-integrator/) will create **ENTER** and **EXIT** events on every geofence border crossing by device, depending on the configuration of geofence `eventTypes`, `eventSources` and also device location update frequency.

<div style={{textAlign: 'center'}}>
![Geofence EXIT event from GPS source](/img/1nce-os/1nce-os-device-locator/device-locator-geofencing-guide/Geofence-event-in-aws-intergration.png)

*Geofence EXIT event from GPS source in AWS Cloud Integration*
</div>

Please see [Cloud integrator output format](/docs/1nce-os/1nce-os-cloud-integrator/cloud-integrator-output-format) for details of geofence events.
