Geofences

  1. Geofences in the interface
  2. Geofences in the API
    1. API methods for working with geofences
    2. Using geofences from the master data
    3. Set geofences using coordinates

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 orders are being assigned, geofence incompatibility is taken into account: both the global option and the values set for individual couriers. When planning routes, you can also cancel all limits related to geofences.

Geofences in the interface

You can work with geofences using the Planning interface and an Excel file:

  1. Define geofences in Master data → Geofences (for more information, see Geofence list).
  2. Select an Excel file and upload it to the interface.
  3. 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.

Geofences in the API

You can work with geofences in the API in one of the following ways:

Using geofences from the master data

For more information on working with the master data via the interface, see Working with geofence data.

To use geofences from the master data, send a request to the mvrp with authorization resource:

curl -H "Content-Type: application/json" -H "Authorization: Auth your-OAuth-token" -X POST -d <request body> https://courier.yandex.ru/api/v1/vrs/add/mvrp
Copied to clipboard

In the Authorization: Auth your-OAuth-token header, replace your-OAuth-token with the OAuth token that you obtained to work with Track & Trace.

Attention.

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:

  1. Draw the zone using the Polygons tool (for more information, see Create item in Yandex Map Constructor Help).
  2. Click Save and continue → Export (for more information, see Exporting map items in Yandex Map Constructor Help).
  3. Select GeoJSON → Download.
  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
                            ]
                        ]
                    ]
                }
            }
            
        ]
    Copied to clipboard

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>
Copied to clipboard

Contact support