Geofences
You can use geofences to set restrictions when planning routes and take into account vehicle characteristics, access conditions, and terrain features. For more information, see Vehicle.
When assigning orders, the algorithm takes into account geofence incompatibilities — both set by the global option and specified for individual couriers. When planning routes, you can also cancel all geofence restrictions.
Note
You can add no more than 500 geofences for a single company.
Geofences in the interface
You can work with geofences using the Planning interface and an Excel file:
- Define geofences in Master data → Geofences (for more information, see Geofence master data).
- Select an Excel file and upload it to the interface.
- When you manage optimization settings on the Settings tab, select Consider geofences → Yes.
When planning routes, orders will be automatically assigned to zones by their coordinates.
You can also use public geofences.
Geofences in the API
You can work with geofences in the API in one of the following ways:
- Using API methods.
- Using geofences from the master data.
- Setting geofence boundaries by coordinates in the planning task.
API methods for working with geofences
API methods can be effectively used in the following cases:
- You create and edit geofences in a third-party service, update the geofence master data in RouteQ, and then use this master data for planning.
- You create and edit geofences in the RouteQ interface and then upload them to your corporate system using methods such as Get company zone or Get company zone reference book.
To manage geofences using the API, send a request to the resource mvrp with OAuth authorization:
curl -H "Content-Type: application/json" -H "Authorization: OAuth <your-token>" -X POST -d <request body> https://courier.yandex.ru/api/v1/vrs/add/mvrp
In the Authorization: OAuth <your-token>
header, change <your-token>
to the OAuth token that you received for Track & Trace.
Alert
The path in the authorization request (with an OAuth token) is different from the path indicated in the specifications (with an API key).
Set geofences using coordinates
To set geofence coordinates directly in the planning task, create the zones
object in the request. Each element of this object describes one geofence and contains the coordinates of the polygon vertices.
To get the coordinates, use the [Yandex Map Constructor] tools (https://yandex.com/map-constructor:
-
Draw the zone using the Polygons tool (for more information, see Create item in Yandex Map Constructor Help).
-
Click Save and continue → Export (for more information, see Exporting map items in Yandex Map Constructor Help).
-
Select GeoJSON → Download.
-
Use the
geometry
item in the request to form thezones
item.Sample geofence description in a request
"zones": [ { "id": "zone1", "geometry": { "type": "Polygon", "coordinates": [ [ [ 37.3890158054755, 55.8142956464218 ], [ 37.4755331394599, 55.7415407888477 ], [ 37.5716635105537, 55.7984405246533 ], [ 37.5847097752021, 55.799987651288 ], [ 37.3890158054755, 55.8142956464218 ] ] ] } } ]
To set geofences using coordinates, send a request to the mvrp resource:
curl -H "Content-Type: application/json" -X POST -d <request body> https://courier.yandex.ru/vrs/api/v1/add/mvrp?apikey=<API key>