How to create geofences using REST

This guide shows how to create different kinds of geofences using REST API.

Read more about geofences in GpsGate here.

Requisites

The Geofences REST API resource will require the following information to be entered, read here how to obtain them:

Resource used

  • Geofences > Post

Creating a circular geofence

1. Log in to http://host_name/comGpsGate/api/v.1/test 

Note: replace host_name with your actual server IP address or host name.

2. Navigate to Geofences. Click on the resource name POST/applications/...../geofences > Try it out option.

mceclip0.png

3. You will be required to enter any of the 3 geofences models available for each geofence type:

  • Circular geofences
  • Polygon geofences
  • Route geofences

We will enter the Circular geofence model this way:

{
"shapeType": "Circle",
"name": "GpsGate office",
"description": "",
"circleShape": {
"radius": 100,
"center": {
"longitude": 18.03068,
"latitude": 59.33583
}
},
},

4. Click on Execute

Screenshot 2024-07-23 at 09.54.06.png

If everything went well, you will see the "200" status in the response, with a geofence ID generated:

Screenshot 2024-07-23 at 09.55.05.png

Note that in the application, you will see your geofence under Ungrouped geofences

Screenshot 2024-07-23 at 09.56.16.png

Creating a polygon geofence

To create a polygon, follow the same number of steps as a circle. For the shape model, use instead the following example as a reference (this polygon contains four vertices):

{
"shapeType": "Polygon",
"name": "Polytest",
"description": "",
"polygonShape": {
"vertices": [
{
"longitude": 18.049890518188477,
"latitude": 59.348228454589844
},
{
"longitude": 18.050880432128906,
"latitude": 59.34706115722656
},
{
"longitude": 18.054359436035156,
"latitude": 59.34751892089844
},
{
"longitude": 18.053640365600586,
"latitude": 59.348899841308594
},
{
"longitude": 18.049890518188477,
"latitude": 59.348228454589844
}
]
},
}

This model should create this polygon geofence on the map:

Screenshot 2024-07-23 at 09.35.42.png

Creating a route geofence

To create a Route Geofence, follow the same number of steps as the previous ones. For the shape model, use instead the following example as a reference:

{
"shapeType": "Route",
"name": "Highway",
"description": "",
"routeShape": {
"vertices": [
{
"longitude": 18.046859741210938,
"latitude": 59.347999572753906
},
{
"longitude": 18.04612922668457,
"latitude": 59.34782028198242
},
{
"longitude": 18.047000885009766,
"latitude": 59.34693908691406
},
{
"longitude": 18.04707908630371,
"latitude": 59.346858978271484
},
{
"longitude": 18.04865074157715,
"latitude": 59.34727096557617
},
{
"longitude": 18.049619674682617,
"latitude": 59.34751892089844
},
{
"longitude": 18.05143928527832,
"latitude": 59.347999572753906
},
{
"longitude": 18.051620483398438,
"latitude": 59.34804153442383
},
{
"longitude": 18.052310943603516,
"latitude": 59.347320556640625
},
{
"longitude": 18.053129196166992,
"latitude": 59.346439361572266
},
{
"longitude": 18.053199768066406,
"latitude": 59.34635925292969
},
{
"longitude": 18.053510665893555,
"latitude": 59.346439361572266
}
],
"radius": 3.6469114871954655
},
}

This model should create the following route geofence on the map:

Screenshot 2024-07-23 at 09.35.50.png