最初这个问题及其前身是在R-Sig-Geo上提出来的:
https://stat.ethz.ch/pipermail/r-sig-geo/2012-July/015648.html
“mow.R”包含:
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)
从R执行此操作会导致:
> 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'
>
我复制了它的网址并将其粘贴到浏览器中:
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
它产生了以下信息:
Google Maps API服务器拒绝了您的请求。 “传感器” 请求中指定的参数必须设置为“true”或 “假”。
当我在上面的网址中更改“&sensor=false
”的位置时,它可以正常工作:
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
如何将此更改合并到“mow.R”文件中? 请帮忙;
答案 0 :(得分:2)
您不只是更改传感器参数的位置。在您的第二个网址中,您可以在第一个网址上正确设置它,因为您错过了&符号&amp;'在假值之后。
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
应该是:
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