ggooglemaps: Contructor for Google maps widget

Description Usage Arguments Details Value Author(s) References

View source: R/ggooglemaps.R


This creates a widget to show a map provided by Google. One can specify the center of the map, markers on the map and add line semgemnts and polygons. This extension to gWidgets is gWidgetsWWW specific.


ggooglemaps(x, title = "", type = c("map", "panorama"), 
key = "ABQIAAAAYpRTbDoR3NFWvhN4JrY1ahS5eHnalTx_x--TpGz1e2ncErJceBS7FrNBqzV5DPxkpbheIzZ9nTJPsQ",
container, ...)



Location of center of map. Given as a string containing an address, or as a vector of latitude and longitude values.


The center is marked. This sets the text for the tooltip.


Determines type of map. One of "map" or "panorama".


A google API key. The default is for localhost, which hopefully just works.


A gWidgetsWWW container object




This widget was created using the code posted to the ExtJS blog by Shea Frederick .

This widget requires the HTML page that will render it have the DOCTYPE of the page set according to these instructions:

Next, the website the page will be listed on must register to have an API key: NOT WORKING:This key is specifies through the key argument. The default will work for the domain

The key can be specified in the header of the html page that will render the gWidgets code. The following will work for the domain

<script src="" type="text/javascript"></script>

This widget is experimental. Its API is still not settled. As of now, the method svalue<- is used to set the center of the map. After rendering this is done using a data vector of longitude and latitude. Prior to rendering an address can be used.

The [ method will return the markers locations, but does not reflect their position after if they are moved with the mouse.

The [$<$- method can be used to set markers. The value can These are specified in a 2 or 3 column data frame with columns of latitude, longitude and the optional title. After the widget has rendered, the proto method widget$addMarker is more efficient.

The handlers addHandlerClicked and addHandlerDoubleclick should work. The first argument of the handler, h, is, as usual, a list. The component latlng contains a vector with the latitude and longitude of the location the mouse click occurred at.

More of the Google maps API is availble through some proto methods. These methods are called using the dollar sign notation, as in widget\$methodname(methodargs).

The available proto methods and their signatures are:


Returns a list with the lower and upper coordinates of the current map.


Sets map center to new coordinates specified using a numeric vector of latitude and longitude.


Sets new zoom value. Default is 14

widget\$openInfoWindow(latlng, myHTML)

Pops up message at point specified by latlng

widget\$addMarker(latlng, title, draggable=FALSE)

Add a new marker at the specified point with tooltip. These markers may be draggable. A popup shows the new coordinates after dragging. However, the values returned by [ are not aware of the new coordinates.

widget\$addPolyline(latlng, color = "\#ff0000", pixel.width = 5, opacity = 1

Like the lines graphic function, this method adds line segments to the map. The points are specified in latlng, which is a matrix or data frame with columns of latitude and longitude values. If this is missing, the values set via [$<$- and addMarker are used. The color is set using hexadecimal RGB notation, eg. "\#ff0000". Opacity levels less than 1 allow the map to bleed through. When the line is clicked, its length in meters is given.

widget\$addPolygon(latlng,border.color="\#ff0000", border.pixel.width = 5,border.opacity = 1,region.color = "\#000000",region.opacity = .1)

Like the polygon graphics function, this method draws a polygon, rendering it on the map. The points are specified by a matrix (or data.frame) to latlng. If missing, the values set via [$<$- or addMarker are used.. When the polygon is clicked its area in square meters is presented.

Adding additional methods from the Google API is certainly possible.


Returns a gWidgetsWWW object.


John Verzani


gWidgetsWWW documentation built on May 2, 2019, 4:47 p.m.