mb_directions: Make a request to the Mapbox Directions API

View source: R/route.R

mb_directionsR Documentation

Make a request to the Mapbox Directions API

Description

See the Mapbox Directions API documentation for more information.

Usage

mb_directions(
  input_data = NULL,
  origin = NULL,
  destination = NULL,
  profile = "driving",
  output = "sf",
  depart_at = NULL,
  alternatives = NULL,
  annotations = NULL,
  bearings = NULL,
  continue_straight = NULL,
  exclude = NULL,
  geometries = "geojson",
  overview = "simplified",
  radiuses = NULL,
  approaches = NULL,
  steps = NULL,
  banner_instructions = NULL,
  language = NULL,
  roundabout_exits = NULL,
  voice_instructions = NULL,
  voice_units = NULL,
  waypoint_names = NULL,
  waypoint_targets = NULL,
  waypoints = NULL,
  walking_speed = NULL,
  walkway_bias = NULL,
  alley_bias = NULL,
  access_token = NULL
)

Arguments

input_data

An input dataset of class "sf", or a list of coordinate pairs for format c(longitude, latitude). Cannot be used with an origin/destination pair.

origin

An address or coordinate pair that represents the origin of your requested route. Cannot be used with input_data.

destination

An address or coordinate pair that represents the destination of your requested route.

profile

One of "driving" (the default), "driving-traffic", "walking", or "cycling".

output

One of "sf" (the default), which returns an sf LINESTRING representing the route geometry, or "full", which returns the full request from the Directions API as a list.

depart_at

(optional) For the "driving" or "driving-traffic" profiles, the departure date and time to reflect historical traffic patterns. If "driving-traffic" is used, live traffic will be mixed in with historical traffic for dates/times near to the current time. Should be specified as an ISO 8601 date/time, e.g. "2022-03-31T09:00".

alternatives

Whether or not to return alternative routes with your request. If TRUE, a list of up to 3 possible routes will be returned.

annotations

A comma-separated string of additional route metadata, which may include duration, distance, speed, and congestion. Must be used with overview = "full".

bearings

A semicolon-delimited character string of bearings

continue_straight

continue_straight

exclude

Road types to exclude from your route; possible choices are 'toll', 'motorway', or 'ferry'. Defaults to NULL.

geometries

The route geometry format. If output = 'sf', you will get back an sf object and you should leave this blank. If output = 'full', the embedded route geometries will be one of 'geojson' (the default), 'polyline' with five decimal place precision, or 'polyline6'.

overview

If left blank, defaults to 'simplified' for simplified geometry; the other option is 'full' which provides the most detailed geometry available.

radiuses

A character string with semicolon-separated radii that specify the distance (in meters) to snap each input coordinate to the road network. Defaults to NULL.

approaches

A character string with semicolon-separated specifications for how to approach waypoints. Options include unrestricted and curb. Defaults to NULL which uses unrestricted for all waypoints.

steps

If TRUE, returns the route object split up into route legs with step-by-step instructions included. If FALSE or NULL (the default), a single line geometry representing the full route will be returned.

banner_instructions

Whether or not to return banner objects; only available whenoutput = 'full' and steps = TRUE.

language

The language of the returned instructions (defaults to English). Available language codes are found at https://docs.mapbox.com/api/navigation/#instructions-languages. Only available when steps = TRUE.

roundabout_exits

If TRUE, adds instructions for roundabout entrance and exit. Only available when steps = TRUE.

voice_instructions, voice_units

Only available when steps = TRUE and output = 'full'.

waypoint_names, waypoint_targets, waypoints

Only available when steps = TRUE and output = 'full'.

walking_speed

The walking speed in meters/second; available when profile = 'walking'.

walkway_bias

Can take values between -1 and 1, where negative numbers avoid walkways and positive numbers prefer walkways. Available when profile = 'walking'.

alley_bias

Can take values between -1 and 1, where negative numbers avoid alleys and positive numbers prefer alleys. Available when profile = 'walking'.

access_token

A Mapbox access token; which can be set with mb_access_token()

Value

An sf object (or list of sf objects), or full R list representing the API response.

Examples

## Not run: 
library(mapboxapi)
library(leaflet)

my_route <- mb_directions(
  origin = "10 Avenue de Wagram, 75008 Paris France",
  destination = "59 Rue de Tocqueville, 75017 Paris France",
  profile = "cycling",
  steps = TRUE,
  language = "fr"
)

leaflet(my_route) %>%
  addMapboxTiles(
    style_id = "light-v9",
    username = "mapbox"
  ) %>%
  addPolylines()

## End(Not run)

mapboxapi documentation built on Sept. 21, 2024, 1:06 a.m.