Learn R Programming

ggmap (version 2.2)

mapdist: Compute map distances using Google

Description

Compute map distances using Google Maps

Usage

mapdist(from, to,
    mode = c("driving", "walking", "bicycling"),
    output = c("simple", "all"), messaging = FALSE,
    sensor = FALSE, language = "en-EN",
    override_limit = FALSE)

Arguments

from
name of origin addresses in a data frame (vector accepted)
to
name of destination addresses in a data frame (vector accepted)
output
amount of output
mode
driving, bicycling, or walking
messaging
turn messaging on/off
sensor
whether or not the geocoding request comes from a device with a location sensor
language
language
override_limit
override the current query count (.GoogleDistQueryCount)

Value

  • a data frame (output='simple') or all of the geocoded information (output='all')

Details

if parameters from and to are specified as geographic coordinates, they are reverse geocoded with revgeocode. note that the google maps api limits to 2500 element queries a day.

See Also

http://code.google.com/apis/maps/documentation/distancematrix/

Examples

Run this code
from <- c('houston, texas', 'dallas')
to <- 'waco, texas'
mapdist(from, to)
mapdist(from, to, mode = 'bicycling')
mapdist(from, to, mode = 'walking')

from <- c('houston', 'houston', 'dallas')
to <- c('waco, texas', 'san antonio', 'houston')
mapdist(from, to)

mapdist('the white house', 'washington monument', mode = 'walking')

# geographic coordinates are accepted as well
(wh <- as.numeric(geocode('the white house')))
(wm <- as.numeric(geocode('washington monument')))
mapdist(wh, wm, mode = 'walking')
mapdist('the white house', wm, mode = 'walking')
distQueryCheck()

Run the code above in your browser using DataLab