Source: https://maps.vietmap.vn/docs/map-api/geofencing/ # Geofencing API [![geofencing]][geofencing] [geofencing]: https://maps.vietmap.vn/docs/assets/geofencing-jpg.webp **Geofencing** means checking whether a position falls inside a virtual boundary drawn around a real-world place. The VIETMAP Geofencing API takes a position (vehicle, device) together with a list of zone centers and a radius in metres, and returns `inside: true/false` per center. Each request is an independent check: the API stores no fences and emits no events. To detect enter/exit, call it on every position update and compare with the previous result. ## What you can build with it | Use case | What the geofence does | | --- | --- | | **Proof of delivery** | Confirm the vehicle actually reached the customer address before the driver marks the order delivered. | | **Fleet compliance** | Alert when a truck leaves its permitted operating zone or enters a restricted district. | | **Automatic trip records** | Start and stop a trip when a vehicle leaves and returns to the depot, without the driver touching anything. | | **Site attendance** | Record staff arriving at and leaving a construction site or branch. | | **Proximity marketing** | Notify a customer when they are near one of your stores. | | **Asset protection** | Raise an alarm the moment equipment moves outside the yard it belongs to. | ## Geofence vs. isochrone A **geofence** is a zone *you* define by center and radius and check positions against. An **[isochrone](https://maps.vietmap.vn/docs/map-api/isochrone/)** is a boundary VIETMAP *computes* — the area reachable within a given travel time. They pair naturally: compute an isochrone to decide what a sensible serving area looks like, then use that area's center and an approximate radius as the geofence. URL --- ```swift https://maps.vietmap.vn/api/geofencing?apikey={your-apiKey} ``` Method --- **POST** Parameters --- |Parameter|Type|Required|Default|Description| |--- |--- |--- |--- |--- | |apikey|string|yes|none|API key provided by VIETMAP for your account. [Register here](https://maps.vietmap.vn/console-v2/register)| Example --- ```swift URL: https://maps.vietmap.vn/api/geofencing?apikey=”YOUR APIKEY” ``` ```json Body: { "geometryCenters": [ { "id": "1", "long": 105.7487405, "lat": 9.8644254 }, { "id": "2", "long": 105.7491342, "lat": 9.8642686 }, { "id": "3", "long": 105.7489267, "lat": 9.8645398 } ], "radius": 15, "long": 105.7488398, "lat": 9.8643837 } ``` ### Request body description | Parameter | Type | Description | |------------------|---------|------------------------------------------------------------------------| | geometryCenters | array | Centers of the zones to check against, one object per zone. | | geometryCenters.id | string | The identifier of the geometry center. | | geometryCenters.long | number | The longitude coordinate of the geometry center. | | geometryCenters.lat | number | The latitude coordinate of the geometry center. | | radius | number | Radius in metres, applied to every center in `geometryCenters`. `inside` is `true` when the position is within `radius` of the center. | | long | number | Longitude of the position to check (vehicle, device). | | lat | number | Latitude of the position to check (vehicle, device). | Response --- ```json { "code": null, "message": null, "data": [ { "id": "1", "inside": true }, { "id": "2", "inside": false }, { "id": "3", "inside": false } ] } ``` ### Response description | Field | Type | Description | |------------|---------|----------------------------------------------------------------------| | code | null | Error code. `null` on success. | | message | null | Error message. `null` on success. | | data | array | One entry per center in `geometryCenters`. | | data.id | string | The `id` you sent for this zone. | | data.inside| boolean | `true` if the position is within `radius` of this center, otherwise `false`. |