首页 > 解决方案 > How do I update the centre value for get_googlemap in the ggmap package?

问题描述

I am trying to obtain a map of a part of London (England) using the ggmap package in R, coordinates -0.205, 51.516. However, when obtaining/plotting the map, the centre constantly defaults to 29.763284,-95.36327 (somewhere in Houston, Texas). For example, see the structure of the link below - nb: it's not navigable without a valid API key.

Source : https://maps.googleapis.com/maps/api/staticmap?center=29.763284,-95.363271&zoom=16&size=640x640&scale=2&maptype=satellite&key=[xxx-last_part_of_my_API_key]

I've tried to use alternative coordinates but the result is always the same. Have also tried to use an alternative API keys to no avail. My stripped down code is as follows:

library(ggmap)

register_google(key = "[my API key]")
has_google_key()

test <- get_googlemap(location = c(lon=-0.205, lat=51.516),
                zoom = 16, maptype = "satellite",color="bw")

ggmap(test)

The expected result is that centre will update to -0.205, 51.516 and show a portion of Portobello Road as a black and white Satellite Google map tile. Suggestions and comments are most welcome - go easy, I'm new here! Apologies if this question has already been asked/addressed.

标签: rggmap

解决方案


我认为应该center代替location.

test <- get_googlemap(center = c(lon=-0.205, lat=51.516),
                zoom = 16, maptype = "satellite",color="bw")

默认值为center = c(lon = -95.3632715, lat = 29.7632836),即休斯顿市中心。


推荐阅读