-1

最初这个问题及其前身是在 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 服务器拒绝了您的请求。请求中指定的“sensor”参数必须设置为“true”或“false”。

当我更改&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”文件中? 请帮忙;

4

1 回答 1

2

您不只是更改传感器参数的位置。在您的第二个 URL 中,您正确设置了它,在第一个 URL 上您根本没有设置它,因为您在 false 值之后缺少一个 & 符号。

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
于 2012-07-16T13:58:49.970 回答