Reputation: 785
I am trying to create map of California state following the ggmap link. However,when I am running the below code it is giving me below error.
get_map(location ='california',zoom =4)
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=california&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=california&sensor=false 1280x1280 terrain map image from Google Maps. see ?ggmap to plot it.
In addition, I am planning on trying to plot some location on same map. Any help is much appreciated.
My dataset for plotting latitude and longitude looks like following:
structure(list(hotel_name = structure(c(1L, 5L, 2L, 4L, 3L), .Names = c("h1_Loc",
"h2_Loc", "h3_Loc", "h4_Loc", "h5_Loc"), .Label = c("Grand Hyatt San Diego",
"Grand Hyatt San Francisco", "Hyatt Regency Orange County", "Hyatt Regency Sacramento",
"Hyatt Regency San Francisco"), class = "factor"), longi = c(-117.1687,
-122.3954, -122.4073, -121.4908, -117.9164), lati = c(32.70974,
37.79459, 37.78922, 38.57763, 33.78932)), .Names = c("hotel_name",
"longi", "lati"), row.names = c("h1_Loc", "h2_Loc", "h3_Loc",
"h4_Loc", "h5_Loc"), class = "data.frame")
Upvotes: 0
Views: 2204
Reputation: 15369
Expanding upon JasonAizkaln's answer, but the get_map
function just downloads the tile from google maps. The message shown is not an error, but just a message to let you know about this download.
If you want to disable the message, you can add messaging = FALSE
to get_map
, as explained in the documentation.
To plot the result, you need to use the ggmap
function, which creates a typical ggplot object:
map <- get_map(location ='california',zoom = 4)
ggmap(map)
You can easily add data to this using the standard ggplot functions. Loading your supplied data as df
, we can plot the points as follows:
map <- get_map(location ='california',zoom = 5)
ggmap(map) +
geom_point(data = df, aes(x =longi, y = lati))
Upvotes: 0