distanceMatrix: Get driving distance and driving time matrices between...

Description Usage Arguments Details Value Examples

View source: R/distanceMatrix.R

Description

Get driving distance and driving time matrices between coordinates using the Google Maps Distance Matrix API (requires API key).

Usage

1
distanceMatrix(origins, destinations, units = "metric", key, pause.time = 0.02)

Arguments

origins

Origin points. A matrix/data.frame of coorindates where the first column are the longitudes and the second column are the latitudes.

destination

Destination points. A matrix/data.frame of coorindates where the first column are the longitudes and the second column are the latitudes. This can be the same as origin points.

units

Use metric or imperial units. Default is metric.

key

API key. The distance matrix API must be enabled first.

pause.time

Amount of time in seconds to wait after a request (if performing multiple requests in a loop).

Details

An API key must first be obtained to use the API and you need to enable the Distance Matrix API. If you are over your query limit, the function will issue a warning.

Value

distance

Driving distance matrix between origin and destination points. If no route is found it will return NA.

duration

Driving time duration (in seconds) between origin and destination points. If no route is found it will return NA.

origin_addresses

The addresses of the origin points.

destination_addresses

The addresses of the destination points.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  ## Not run: 
  places <- rbind(geocodeAddress("Boston")$crd,
                  geocodeAddress("New York")$crd,
                  geocodeAddress("Washington DC")$crd)
  # Format looks like this:
  #            lon      lat
  # [1,] -71.05888 42.36008
  # [2,] -74.00594 40.71278
  # [3,] -77.03687 38.90719
  distanceMatrix(origins = places, destinations = places, key = YOUR.API.KEY)
  
## End(Not run)

walshc/GoogleMapsAPI documentation built on May 3, 2019, 11:50 p.m.