ggooglemaps {gWidgetsWWW} | R Documentation |
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, ...)
x |
Location of center of map. Given as a string containing an address, or as a vector of latitude and longitude values. |
title |
The center is marked. This sets the text for the tooltip. |
type |
Determines type of map. One of "map" or "panorama". |
key |
NOT WORKING! SEE BELOW. To use a google map, one must register their domain and get a "key" from Google. The default key is for the domain 127.0.0.1:8079, the Rpad local server default. To use a different domain, one must specify a new key here after getting it from http://code.google.com/apis/maps |
container |
A gWidgetsWWW container object |
... |
This widget was created using the code posted to the ExtJS blog by Shea Frederick http://extjs.com/blog/2008/07/01/integrating-google-maps-api-with-extjs/ .
This widget requires the HTML page that will render it have the DOCTYPE of the page set according to these instructions: http://code.google.com/apis/maps/documentation/index.html#XHTML_and_VML
Next, the website the page will be listed on must register to have an
API key: http://code.google.com/apis/maps/signup.html. NOT WORKING:This key is
specifies through the key
argument. The default will work for the domain 127.0.0.1:8079
.
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 127.0.0.1:8079:
<script
src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAYpRTbDoR3NFWvhN4JrY1ahS5eHnalTx_x--TpGz1e2ncErJceBS7FrNBqzV5DPxkpbheIzZ9nTJPsQ"
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:
latlng
[
are not aware of the new coordinates.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.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
http://extjs.com/blog/2008/07/01/integrating-google-maps-api-with-extjs/, http://code.google.com/apis/maps/