Originally this question and its precursor were asked on R-Sig-Geo:
https://stat.ethz.ch/pipermail/r-sig-geo/2012-July/015648.html
The "mow.R" contains:
library (RgoogleMaps)
png (filename="RgoogleMaps-package_%03d_med.png", width=480, height=480)
MyMap <- GetMap(markers =
'40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc',
sensor = "false", destfile = "MyTile1.png");
tmp <- PlotOnStaticMap(MyMap,lat = c(40.702147,40.711614,40.718217),
lon = c(-74.015794,-74.012318,-73.998284), cex=1.5,pch=20,col=c('red',
'blue', 'green'), add=F)
Executing this from R results in:
> source('mow.R')
[1] "Note that when center and zoom are not specified, no meta
information on the map tile can be stored. This basically means that R
cannot compute proper coordinates. You can still download the map tile
and view it in R but overlays are not possible. Do you want to proceed
? (y/n)"
y
[1] "40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
[1] "http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=false40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc"
Error in download.file(url, destfile, mode = "wb", quiet = TRUE) :
cannot open URL
'http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=false40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc'
In addition: Warning message:
In download.file(url, destfile, mode = "wb", quiet = TRUE) :
cannot open: HTTP status was '403 Forbidden'
>
I copied its url and pasted it in the browser:
http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=false40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc
It resulted in the following message:
The Google Maps API server rejected your request. The "sensor" parameter specified in the request must be set to either "true" or "false".
When I change the position of "&sensor=false
" in the above url, it works fine:
http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png3240.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc&sensor=false
How to incorporate this change in the "mow.R" file now? Please help;
You are not just changing the position of the sensor parameter. In your second URL you set it properly, on the first URL you don't set it at all because you're missing an ampersand '&' after the false value.
http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=false40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc
Should be:
http://maps.google.com/maps/api/staticmap?size=640x640&maptype=terrain&format=png32&sensor=false&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc