seo_title: "Geofencing API – Virtual Boundaries & Alerts | VIETMAP" description: "Define virtual boundaries anywhere in Vietnam and detect when a vehicle or device enters or leaves them, for delivery proof and fleet compliance." keywords: geofencing api, geofence api, virtual boundary api, enter exit detection, API hàng rào địa lý, geofencing là gì, cảnh báo ra vào vùng, giám sát đội xe
Geofencing API¶
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 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¶
Method¶
POST
Parameters¶
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| apikey | string | yes | none | API key provided by VIETMAP for your account. Register here |
Example¶
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
}
curl -X POST 'https://maps.vietmap.vn/api/geofencing?apikey=YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"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}'
// Node.js 18+. Call from your server so the API key stays private.
const 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
};
const res = await fetch("https://maps.vietmap.vn/api/geofencing?apikey=YOUR_API_KEY", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const data = await res.json();
console.log(data);
import requests
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
}
resp = requests.post("https://maps.vietmap.vn/api/geofencing?apikey=YOUR_API_KEY", json=body, timeout=30)
resp.raise_for_status()
print(resp.json())
Integrate the VIETMAP Geofencing API into my project.
Sample request (from the example in the docs):
POST https://maps.vietmap.vn/api/geofencing
Body (JSON): {"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}
Requirements:
- Call the API from the server. Read the API key from the VIETMAP_API_KEY environment variable and send it as `apikey`; never hard-code it.
- Write one function that sends this request, checks the HTTP status and returns the parsed response.
- Read the docs below first. Use only parameters and response fields documented there.
Docs:
- https://maps.vietmap.vn/docs/map-api/geofencing/index.txt
- https://maps.vietmap.vn/docs/assets/agents/logistics.txt
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¶
{
"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. |
Related APIs¶
- Map Matching — reconstruct the driven route from the same GPS feed.
- Reverse v4 — the address at a vehicle's position.
- VRP — plan the stops a geofence then confirms.
