ggmap (version 2.6.2)

get_googlemap: Get a Google Map.

Description

get_googlemap accesses the Google Static Maps API version 2 to download a static map. Note that in most cases by using this function you are agreeing to the Google Maps API Terms of Service at https://developers.google.com/maps/terms.

Usage

get_googlemap(center = c(lon = -95.3632715, lat = 29.7632836), zoom = 10,
  size = c(640, 640), scale = 2, format = c("png8", "gif", "jpg",
  "jpg-baseline", "png32"), maptype = c("terrain", "satellite", "roadmap",
  "hybrid"), language = "en-EN", sensor = FALSE, messaging = FALSE,
  urlonly = FALSE, filename = "ggmapTemp", color = c("color", "bw"),
  force = FALSE, where = tempdir(), archiving = FALSE, key = "", region,
  markers, path, visible, style, ...)

Arguments

center

the center of the map. Either a longitude/latitude numeric vector, a string address (note that the latter uses geocode with source = "google").

zoom

map zoom, an integer from 3 (continent) to 21 (building), default value 10 (city)

size

rectangular dimensions of map in pixels - horizontal x vertical - with a max of c(640, 640). this parameter is affected in a multiplicative way by scale.

scale

multiplicative factor for the number of pixels returned possible values are 1, 2, or 4 (e.g. size = c(640,640) and scale = 2 returns an image with 1280x1280 pixels). 4 is reserved for google business users only. scale also affects the size of labels as well.

format

character string providing image format - png, jpeg, and gif formats available in various flavors

maptype

character string providing google map theme. options available are "terrain", "satellite", "roadmap", and "hybrid"

language

character string providing language of map labels (for themes with them) in the format "en-EN". not all languages are supported; for those which aren't the default language is used

sensor

specifies whether the application requesting the static map is using a sensor to determine the user's location

messaging

turn messaging on/off

urlonly

return url only

filename

destination file for download (file extension added according to format)

color

color or black-and-white

force

if the map is on file, should a new map be looked up?

where

where should the file drawer be located (without terminating "/")

archiving

use archived maps. note: by changing to TRUE you agree to the one of the approved uses listed in the Google Maps API Terms of Service : http://developers.google.com/maps/terms.

key

an api_key for business users

region

borders to display as a region code specified as a two-character ccTLD ("top-level domain") value, see http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains

markers

data.frame with first column longitude, second column latitude, for which google markers should be embedded in the map image, or character string to be passed directly to api

path

data.frame (or list of data.frames) with first column longitude, second column latitude, for which a single path should be embedded in the map image, or character string to be passed directly to api

visible

a location as a longitude/latitude numeric vector (or data frame with first column longitude, second latitude) or vector of character string addresses which should be visible in map extent

style

character string to be supplied directly to the api for the style argument or a named vector (see examples). this is a powerful complex specification, see https://developers.google.com/maps/documentation/staticmaps/

...

...

Value

a ggmap object (a classed raster object with a bounding box attribute)

See Also

https://developers.google.com/maps/documentation/staticmaps/, ggmap

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
 # to diminish run check time


get_googlemap(urlonly = TRUE)
ggmap(get_googlemap())


# markers and paths are easy to access
d <- function(x=-95.36, y=29.76, n,r,a){
  round(data.frame(
    lon = jitter(rep(x,n), amount = a),
    lat = jitter(rep(y,n), amount = a)
  ), digits = r)
}
df <- d(n=50,r=3,a=.3)
map <- get_googlemap(markers = df, path = df,, scale = 2)
ggmap(map)
ggmap(map, extent = "device") +
  geom_point(aes(x = lon, y = lat), data = df, size = 3, colour = "black") +
  geom_path(aes(x = lon, y = lat), data = df)

gc <- geocode("waco, texas", source = "google")
center <- as.numeric(gc)
ggmap(get_googlemap(center = center, color = "bw", scale = 2), extent = "device")

# the scale argument can be seen in the following
# (make your graphics device as large as possible)
ggmap(get_googlemap(center, scale = 1), extent = "panel") # pixelated
ggmap(get_googlemap(center, scale = 2), extent = "panel") # fine

# archiving; note that you must meet google's terms for this condition
map <- get_googlemap(archiving = TRUE)
map <- get_googlemap()
ggmap(map)


# style
map <- get_googlemap(style = c(feature = "all", element = "labels", visibility = "off"))
ggmap(map)




# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace