离线绘制Google静态地图上的地图坐标

Aqu*_*irl 3 png r ggplot2 google-maps-static-api ggimage

历史记录:从静态Google地图png中提取的栅格数据,将其加载到R设备上ggimage.

library (png)
library (ggmap)

rasterArray <- readPNG ("My.png")

x = c (40.702147,40.718217,40.711614)
y = c (-74.012318,-74.015794,-73.998284)

myData <- data.frame (x, y)

print (ggimage (rasterArray, fullpage = TRUE, coord_equal = FALSE) 
    + geom_point (aes (x = x, y = y), data = myData, colour = I("green"), 
      size = I(5), fill = NA))
Run Code Online (Sandbox Code Playgroud)

我确实运行dput了,rasterArray但输出是20 MB,不能在这里发布.
顺便说一句,这是静态地图的URL:

问:为绘制"GPS坐标"包含的像素地图将R设备上,我需要scaledata.frame

我看到这个页面:http://www-personal.umich.edu/~varel/rdatasets/Langren1644.html 我是否需要按照他们在这里展示的方式进行缩放?

如果是,那么除了scale函数的手册之外的其他内容我还需要了解才能完成这项工作吗?

我在错误的树上吠叫吗?

And*_*rie 22

我认为你的错误如下:

  • 尝试在图像上绘制地理数据,其中该图像不具有对地图坐标的任何感知
  • 可能会在数据框中移调纬度和经度

以下是您应该如何执行此操作,分两步:

  1. 使用获取地图get_map()并将其保存到磁盘save()
  2. 用数据绘制数据 ggmap()

首先,获取地图.

library (ggmap)


# Read map from google maps and save data to file

mapImageData <- get_googlemap(
  c(lon=-74.0087986666667, lat=40.7106593333333), 
  zoom=15
)
save(mapImageData, file="savedMap.rda")
Run Code Online (Sandbox Code Playgroud)

然后,在一个新的会话中:

# Start a new session (well, clear the workspace, to be honest)

rm(list=ls())

# Load the saved file

load(file="savedMap.rda")

# Set up some data

myData <- data.frame(
    lat = c (40.702147, 40.718217, 40.711614),
    lon = c (-74.012318, -74.015794, -73.998284)
)


# Plot

ggmap(mapImageData) +
    geom_point(aes(x=lon, y=lat), data=myData, colour="red", size=5)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述