Generates a google map object
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")
)
data to be used on the map. Either a data.frame, or an sf
object. See details
A valid Google Maps API key.
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.
integer
representing the zoom level of the map (0 is fully zoomed out)
the maximum zoom level which will be displayed on the map
the minimum zoom level which will be displayed on the map
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).
the width of the map
the height of the map
the padding of the map
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
boolean
indicating if a search box should be placed on the map
logical indicating if the map should center on the searched location
logical indicating if the zoom control should be displayed
defines the type of map to display. One of 'roadmap', 'satellite', 'terrain' or 'hybrid'
logical indicating if the map type control should be displayed
logical indicating if the scale control should be displayed
logical indicating if the street view control should be displayed
logical indicating if the rotate control should be displayed
logical indicating if the full screen control should be displayed
vector containing the libraries you want to load. See details
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).
list of options to pass to the split street view.
valid list elements are heading
and pitch
see google_mapOutput
logical indicating if you want geolocation enabled
the type of data to return to R from an interactive environment (shiny), either an R list, or raw json string.
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
visualization - includes the HeatmapLayer for visualising heatmaps https://developers.google.com/maps/documentation/javascript/visualization
geometry - utility functions for computation of geometric data on the surface of the earth, including plotting encoded polylines. https://developers.google.com/maps/documentation/javascript/geometry
places - enables searching for places. https://developers.google.com/maps/documentation/javascript/places
drawing - provides a graphical interface for users to draw polygons, rectangles, circles and markers on the map. https://developers.google.com/maps/documentation/javascript/drawinglayer
google_mapOutput
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