首页 > 解决方案 > `get_map` 映射函数忽略 ggmap 包中的“source”参数

问题描述

使用该函数时get_map(),尽管我使用参数“source”,但我收到一个错误提示,提示提供 google-API-key:

location = colMeans(city[,c('coords_x1', 'coords_x2')])#mitte
names(location) <- c('lat', 'lon')

get_map(location = location, source='osm')
note : locations should be specified in the lon/lat format, not lat/lon.
Error: Google now requires an API key.
       See ?register_google for details.

似乎该参数被忽略了。

标签: rggmap

解决方案


解决方案在于查询中使用“位置”的方式。只要不bbox提供,ggmap 就会在 google 中查找正确的边界框。从此错误发生。因此,以下代码有效:

bbox <- make_bbox(stadt$coords_x1, stadt$coords_x2, f = .05)


map <- get_map(location = bbox, source='osm') 
ggmap(map) + geom_point(data=stadt, aes(x=coords_x1, y=coords_x2, color=akaQuote))

使用 OSM 作为源,必须将边界框传递给get_map函数。


推荐阅读