Learn R Programming

mapboxapi (version 0.2)

mb_geocode: Geocode an address or place description using the Mapbox Geocoding API

Description

Geocode an address or place description using the Mapbox Geocoding API

Perform reverse geocoding for a coordinate pair

Usage

mb_geocode(
  search_text,
  endpoint = "mapbox.places",
  limit = 1,
  types = NULL,
  search_within = NULL,
  language = NULL,
  output = "coordinates",
  access_token = NULL
)

mb_reverse_geocode( coordinates, endpoint = "mapbox.places", limit = 1, language = NULL, types = NULL, output = "text", access_token = NULL )

Arguments

search_text

The text to search, formatted as a character string. Can be an address, a location, or a description of a point of interest.

endpoint

One of 'mapbox.places' (the default) or mapbox.places-permanent. Per Mapbox's terms of service, you are only allowed to save results and perform batch geocoding with the places-permanent endpoint.

limit

How many results to return; defaults to 1 (maximum 10).

types

A vector of feature types to limit to which the search should be limited. Available options include 'country', 'region', 'postcode', 'district', 'place', 'locality', 'neighborhood', 'address', and 'poi'. If left blank, all types will be searched.

search_within

An sf object, or vector representing a bounding box of format c(min_longitude, min_latitude, max_longitude, max_latitude) used to limit search results. Defaults to NULL.

language

The user's language, which can help with interpretation of queries. Available languages are found at https://docs.mapbox.com/api/search/#language-coverage.

output

one of "text" (the default), which will return a character string or list of character strings representing the returned results; output = "sf", returning an sf object; or "full", which will return a list with the full API response.

access_token

The Mapbox access token (required); can be set with mb_access_token.

coordinates

The coordinates of a location in format c(longitude, latitude) for which you'd like to return information.

Value

A character vector, list, or sf object representing the query results.

Examples

Run this code
# NOT RUN {
whitehouse <- mb_geocode("1600 Pennsylvania Ave, Washington DC")

# }
# NOT RUN {
# }
# NOT RUN {
mb_reverse_geocode(c(77.5958768, 12.9667046), limit = 5, types = "poi")

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab