Learn R Programming

mapboxapi (version 0.2)

mb_directions: Make a request to the Mapbox Directions API

Description

Make a request to the Mapbox Directions API

Usage

mb_directions(
  input_data = NULL,
  origin = NULL,
  destination = NULL,
  profile = "driving",
  output = "sf",
  alternatives = NULL,
  annotations = NULL,
  bearings = NULL,
  continue_straight = NULL,
  exclude = NULL,
  geometries = NULL,
  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.

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 polyline with five decimal place precision. 'polyline6' may also be specified.

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 when output = '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

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

voice_units

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

waypoint_names

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

waypoint_targets

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

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

Your Mapbox access token; set with mb_access_token()

Value

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

Examples

Run this code
# 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()

# }

Run the code above in your browser using DataLab