Learn R Programming

RgoogleMaps (version 1.1.9.3)

GetMap: download a static map from the Google server

Description

Query the Google server for a static map tile, defined primarily by its center and zoom. Many additional arguments allow the user to customize the map tile.

Usage

GetMap(center, zoom = 12, markers, path, span, frame, hl, sensor = "true", 
  maptype = c("roadmap", "mobile", "satellite", "terrain", "hybrid", "mapmaker-roadmap", "mapmaker-hybrid")[4], 
  format = c("gif", "jpg", "jpg-baseline", "png8", "png32")[5], 
  size = c(640, 640), destfile = "MyTile.png", RETURNIMAGE = TRUE, GRAYSCALE =FALSE, verbose = 1)

Arguments

center
lat/lon center of map
zoom
Google maps (integer) zoom level. Zoom levels between $0$ (the lowest zoom level, in which the entire world can be seen on one map) to $19$ (the highest zoom level, down to individual buildings) are possible within the normal maps view.
markers
(optional) defines one or more markers to attach to the image at specified locations. This parameter takes a string of marker definitions separated by the pipe character (|)
path
(optional) defines a single path of two or more connected points to overlay on the image at specified locations. This parameter takes a string of point definitions separated by the pipe character (|)
span
(optional) defines a minimum viewport for the map image expressed as a latitude and longitude pair. The static map service takes this value and produces a map of the proper zoom level to include the entire provided span value from the map`s center point.
frame
(optional) specifies that the resulting image should be framed with a colored blue border. The frame consists of a 5 pixel, 55% opacity blue border.
hl
(optional) defines the language to use for display of labels on map tiles. Note that this paramater is only supported for some country tiles; if the specific language requested is not supported for the tile set, then the default language for that tile set
sensor
specifies whether the application requesting the static map is using a sensor to determine the user`s location. This parameter is now required for all static map requests.
maptype
defines the type of map to construct. There are several possible maptype values, including satellite, terrain, hybrid, and mobile.
format
(optional) defines the format of the resulting image. By default, the Static Maps API creates GIF images. There are several possible formats including GIF, JPEG and PNG types. Which format you use depends on how you intend to present the image. JPEG typic
size
desired size of the map tile image. defaults to maximum size returned by the Gogle server, which is 640x640 pixels
destfile
File to save the map image to.
RETURNIMAGE
return image yes/no default: TRUE
GRAYSCALE
Boolean toggle; if TRUE the colored map tile is rendered into a black & white image, see RGB2GRAY
verbose
level of verbosity

Value

  • URL used to download the tile.

Details

The optional markers can be passed either as a string, such as #GetMap(markers = '40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc', destfile = "MyTile1.png") MyMap <- GetMap(markers = 'color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284', destfile = "MyTile1.png") #http://maps.google.com/maps/api/staticmap?size=320x320&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false or as a dataframe: GetMap(markers = cbind.data.frame(lat = c(40.70214, 40.71161), lon = c(-74.01579, -73.9982), size = c('tiny','mid'), col = c('blue', 'red'), char = c('','n')), destfile = "MyTile2.png");

References

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

See Also

GetMap.bbox

Examples

Run this code
#The first step naturally will be to download a static map from the Google server. A simple example:
  
  MyMap <- GetMap(markers = 'color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284', destfile = "MyTile1.png");
  #In this example we let the Static Maps API determine the correct center and zoom level implicitly, based on evaluation of the position of the markers. However, to be of use within R we do need to know the values for zoom and center explicitly, so it is better practice to compute them ourselves and pass them as arguments, in which case meta information on the map tile can be saved as well:
  lat = c(40.702147,40.718217,40.711614);
  lon = c(-74.012318,-74.015794,-73.998284);
  center = c(mean(lat), mean(lon));
  zoom <- min(MaxZoom(range(lat), range(lon)));
  #this overhead is taken care of implicitly by GetMap.bbox();              
  MyMap <- GetMap(center=center, zoom=zoom,markers = 'color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284', destfile = "MyTile1.png");
  #Note that in the presence of markers one often needs to add some extra padding to the latitude range to acoomodate the extent of the top most marker

Run the code above in your browser using DataLab