Skip to content
Prev 7403 / 29559 Next

Plotting shapefiles on top of Google map tiles

Dear Milton,

You need a Google maps API key for this. If you have a Google account,
you can request one for http://localhost/
at http://code.google.com/apis/maps/signup.html

I have made this more explicit by adding a mykey argument to the function:

gmap <- function(xy, maptype='terrain', mykey, ...) {
    require(RgoogleMaps)
	fun = points
	if (inherits(xy, 'Spatial')) {
		b = bbox(xy)
		if (inherits(xy, 'SpatialPoints')) {
			xy = coordinates(xy)
		} else {
			x = unlist(lapply(xy at polygons, function(i)slot(i, 'Polygons')))
			x = lapply(x, function(x)slot(x, 'coords'))
			xy = matrix(ncol=2, nr=0)
			for (i in 1:length(x)) xy = rbind(xy, x[[i]], c(NA,NA))
			fun = lines
		}
	} else {
		b = rbind(range(xy[,1], na.rm=TRUE), range(xy[,2], na.rm=TRUE))
	}
    gm <- GetMap.bbox(key=mykey, lonR=b[1,], latR=b[2,], maptype=maptype)
    tmp <- PlotOnStaticMap(gm, lon=xy[,1], lat=xy[,2], FUN=fun, verbose=0, ... )
}


Robert
On Sun, Jan 17, 2010 at 11:37 PM, milton ruser <milton.ruser at gmail.com> wrote: