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:

  1. Define geofences in Master dataGeofences (for more information, see Geofence master data).
  2. Select an Excel file and upload it to the interface.
  3. When you manage optimization settings on the Settings tab, select Consider geofencesYes.

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:

API methods for working with geofences

API methods can be effectively used in the following cases:

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:

  1. Draw the zone using the Polygons tool (for more information, see Create item in Yandex Map Constructor Help).

  2. Click Save and continueExport (for more information, see Exporting map items in Yandex Map Constructor Help).

  3. Select GeoJSONDownload.

  4. Use the geometry item in the request to form the zones 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>
Contact support