Avoid POIs

Plan a route through your waypoints that keeps a distance from the POIs you choose, such as speed cameras, school entrances or restricted streets. You select the POIs to avoid with the same filters as listing POIs.

How it works

  1. You send 2 to 50 waypoints, in the order the route visits them. Each waypoint is a pair of coordinates or one of your POIs.
  2. Lanewise selects the POIs to avoid with your avoid filters, but only around the route: inside the bounding box of the waypoints, grown by 10% of its diagonal (at least 1 km, at most 10 km).
  3. Every selected POI becomes a circle of radius meters the route must not enter. POIs within radius of a waypoint are skipped, since the route has to reach that waypoint; they are listed in skipped_poi_ids.
  4. You get the fastest route that stays out of the circles, as a GeoJSON line, with its distance, duration and legs.

Routing requires the plan-routes permission. When a waypoint is a POI or you send avoid, the key also needs read-pois. Each call counts as one request towards your rate limit. To try routing without writing code, use the Routing page of the dashboard: its calls don't count towards your quota.

Limits

  • Name
    Waypoints
    Description

    Between 2 and 50 per route.

  • Name
    POIs to avoid
    Description

    Up to 500 around the route. With more, the request returns a 422: narrow the filters or split the route.

  • Name
    Radius
    Description

    Between 10 and 500 meters around each POI. Defaults to 50.

  • Name
    Length
    Description

    When the route avoids at least one POI, the straight-line distance between consecutive waypoints can add up to 150 km at most.

Errors

Besides the usual errors, routing can answer:

  • Name
    422
    Description

    The body is invalid, a POI does not exist in your team, or no route could be planned: a waypoint is too far from a road the profile can use, or the POIs to avoid block every way through. The message says which.

  • Name
    502
    Description

    The routing service failed to answer. Retry in a moment.

  • Name
    503
    Description

    Routing is not available right now, or is busy. Retry later.

422 Unprocessable Entity

{
  "message": "Waypoint 1 is more than 350 m away from a road the profile can use.",
  "errors": {
    "waypoints.1": ["Waypoint 1 is more than 350 m away from a road the profile can use."]
  }
}

POST/v1/routes

Plan a route

Plan a route through the waypoints, avoiding the POIs you select. Requires the plan-routes permission, plus read-pois when you use POIs.

Required attributes

  • Name
    waypoints
    Type
    array
    Description

    2 to 50 locations, in visiting order. Each is either { "latitude", "longitude" } or { "poi_id" } to use the position of one of your POIs.

Optional attributes

  • Name
    profile
    Type
    string
    Description

    driving-car (default), driving-hgv for trucks, cycling-regular or foot-walking.

  • Name
    avoid
    Type
    object
    Description

    The POIs to avoid. Omit it to plan a plain route; send {} to avoid all your POIs around the route.

  • Name
    avoid.attributes
    Type
    object
    Description

    Attribute values to match, keyed by attribute name or ID, as in filtering.

  • Name
    avoid.category_id / avoid.category_name
    Type
    string
    Description

    Only POIs of this category.

  • Name
    avoid.latitude, avoid.longitude, avoid.distance
    Type
    float
    Description

    Only POIs within distance meters of a point, as in filtering.

  • Name
    avoid.country_id / avoid.city_id / avoid.zipcode_id
    Type
    string
    Description

    Only POIs in this place.

  • Name
    avoid.poi_ids
    Type
    array
    Description

    Only these POIs, up to 500 IDs. Unknown IDs return a 422.

  • Name
    avoid.radius
    Type
    integer
    Description

    Meters to keep from each POI, between 10 and 500. Defaults to 50.

All avoid filters combine: a POI must match every filter you send.

Request

POST
/v1/routes
curl https://api.lanewise.app/v1/routes \
  -H "X-API-KEY: {YOUR_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "profile": "driving-car",
    "waypoints": [
      { "latitude": 41.3870, "longitude": 2.1701 },
      { "poi_id": "01JGZ8Q3N5T9B2C4D6F8H0K2M4" }
    ],
    "avoid": { "category_name": "speed-camera", "radius": 100 }
  }'

Response

{
  "data": {
    "profile": "driving-car",
    "distance": 2710.4,
    "duration": 452.9,
    "bbox": [2.1652, 41.387, 2.1744, 41.4036],
    "geometry": {
      "type": "LineString",
      "coordinates": [[2.1701, 41.387], [2.1652, 41.3951], [2.1744, 41.4036]]
    },
    "legs": [
      { "from": 0, "to": 1, "distance": 2710.4, "duration": 452.9 }
    ],
    "waypoints": [
      { "poi_id": null, "latitude": 41.387, "longitude": 2.1701 },
      { "poi_id": "01JGZ8Q3N5T9B2C4D6F8H0K2M4", "latitude": 41.4036, "longitude": 2.1744 }
    ],
    "avoided": {
      "radius": 100,
      "count": 1,
      "poi_ids": ["01JGZ9A1B2C3D4E5F6G7H8J9K0"],
      "skipped_poi_ids": []
    }
  }
}

Response

  • Name
    distance
    Type
    float
    Description

    Length of the route in meters.

  • Name
    duration
    Type
    float
    Description

    Travel time in seconds.

  • Name
    bbox
    Type
    array
    Description

    Bounding box of the route: [west, south, east, north].

  • Name
    geometry
    Type
    object
    Description

    The route as a GeoJSON LineString. Coordinates are [longitude, latitude], ready for most map libraries.

  • Name
    legs
    Type
    array
    Description

    Distance and duration between each pair of consecutive waypoints; from and to are waypoint indexes.

  • Name
    waypoints
    Type
    array
    Description

    The waypoints with their coordinates, including the ones given as poi_id.

  • Name
    avoided
    Type
    object | null
    Description

    The POIs the route was planned around: radius, count, poi_ids, and skipped_poi_ids for the POIs too close to a waypoint to avoid. null when you don't send avoid.