-1

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;

mdsumner
  • 29,099
  • 6
  • 83
  • 91
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • Please don't cross post, the exactly same message was sent to R-sig-geo – johannes Jul 16 '12 at 12:31
  • R-sig-geo is NOT stackoverflow. @jmsigner People aren't same here and there. Different people may have different solutions. – Aquarius_Girl Jul 16 '12 at 12:32
  • Yes but polite users declare cross posting so as to help avoid squandered effort. Down voting here rather than complaining on the R-Sig list :) – mdsumner Jul 16 '12 at 12:35
  • @mdsumner Where should I declare that this is cross posted? In the main question or in the comments? – Aquarius_Girl Jul 16 '12 at 13:38
  • Are you using the newest version of RGoogleMaps? It seems there is a bug in GetMap which generates an invalid url for google maps. – Paul Hiemstra Jul 16 '12 at 14:06
  • @PaulHiemstra I am using this version of Rgooglemaps: http://cran.r-project.org/web/packages/RgoogleMaps/index.html Is this outdated? – Aquarius_Girl Jul 16 '12 at 15:59

1 Answers1

2

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
Marcelo
  • 9,387
  • 3
  • 35
  • 40
  • Aright, that's a relief! I;ll try it out tomorrow. I hope it works. – Aquarius_Girl Jul 16 '12 at 14:00
  • 1
    But this only fixes the url in the browser. There is still the problem it seems that GetMap generates an invalid url for google maps. – Paul Hiemstra Jul 16 '12 at 14:04
  • @ Paul Hiemstra: you're correct, but in any case I don't see any good reason to use third party libraries that implement their own syntax and hide things from the developer, when it is easy enough, well documented and well supported to code Google Maps directly. – Marcelo Jul 16 '12 at 14:11