Learn R Programming

googleway (version 2.7.8)

google_map: Google map

Description

Generates a google map object

Usage

google_map(
  data = NULL,
  key = get_api_key("map"),
  location = NULL,
  zoom = NULL,
  min_zoom = NULL,
  max_zoom = NULL,
  map_bounds = c(-180, -90, 180, 90),
  width = NULL,
  height = NULL,
  padding = 0,
  styles = NULL,
  search_box = FALSE,
  update_map_view = TRUE,
  zoom_control = TRUE,
  map_type = c("roadmap", "satellite", "hybrid", "terrain"),
  map_type_control = TRUE,
  scale_control = FALSE,
  street_view_control = TRUE,
  rotate_control = TRUE,
  fullscreen_control = TRUE,
  libraries = NULL,
  split_view = NULL,
  split_view_options = NULL,
  geolocation = FALSE,
  event_return_type = c("list", "json")
)

Arguments

data

data to be used on the map. Either a data.frame, or an sf object. See details

key

A valid Google Maps API key.

location

numeric vector of latitude/longitude (in that order) coordinates for the initial starting position of the map. The map will automatically set the location and zoom if data is added through one of the various add_ functions. If null, the map will default to Melbourne, Australia.

zoom

integer representing the zoom level of the map (0 is fully zoomed out)

min_zoom

the maximum zoom level which will be displayed on the map

max_zoom

the minimum zoom level which will be displayed on the map

map_bounds

the visible bounds of the map, specified as a vector of four values of the form (xmin, ymin, xmax, ymax) (i.e., the form of the bounding box of `sf` objects).

width

the width of the map

height

the height of the map

padding

the padding of the map

styles

JSON string representation of a valid Google Maps styles Array. See the Google documentation for details https://developers.google.com/maps/documentation/cloud-customization/cloud-based-map-styling

search_box

boolean indicating if a search box should be placed on the map

update_map_view

logical indicating if the map should center on the searched location

zoom_control

logical indicating if the zoom control should be displayed

map_type

defines the type of map to display. One of 'roadmap', 'satellite', 'terrain' or 'hybrid'

map_type_control

logical indicating if the map type control should be displayed

scale_control

logical indicating if the scale control should be displayed

street_view_control

logical indicating if the street view control should be displayed

rotate_control

logical indicating if the rotate control should be displayed

fullscreen_control

logical indicating if the full screen control should be displayed

libraries

vector containing the libraries you want to load. See details

split_view

string giving the name of a UI output element in which to place a streetview representation of the map. Will only work in an interactive environment (shiny).

split_view_options

list of options to pass to the split street view. valid list elements are heading and pitch see google_mapOutput

geolocation

logical indicating if you want geolocation enabled

event_return_type

the type of data to return to R from an interactive environment (shiny), either an R list, or raw json string.

Details

In order to use Google Maps you need a valid Google Maps Web JavaScript API key. See the Google Maps API documentation https://mapsplatform.google.com/

The data argument is only needed if you call other functions to add layers to the map, such as add_markers() or add_polylines. However, the data argument can also be passed into those functions as well.

The data can either be a data.frame containing longitude and latitude columns or an encoded polyline for plotting polylines and polygons, or an sf object.

The supported sf object types are

  • POINT

  • MULTIPOINT

  • LINESTRING

  • MULTILINESTRING

  • POLYGON

  • MULTIPOLYGON

  • GEOMETRY

The libraries argument can be used to turn-off certain libraries from being called. By default the map will load

See Also

google_mapOutput

Examples

Run this code
if (FALSE) {

map_key <- "your_api_key"

google_map(key = map_key, data = tram_stops) %>%
 add_markers() %>%
 add_traffic()

## style map using 'cobalt simplified' style
style <- '[{"featureType":"all","elementType":"all","stylers":[{"invert_lightness":true},
{"saturation":10},{"lightness":30},{"gamma":0.5},{"hue":"#435158"}]},
{"featureType":"road.arterial","elementType":"all","stylers":[{"visibility":"simplified"}]},
{"featureType":"transit.station","elementType":"labels.text","stylers":[{"visibility":"off"}]}]'

google_map(key = map_key, styles = style)

}

Run the code above in your browser using DataLab