简体   繁体   中英

Error in get_googlemap

When I use get_googlemap or get_map, a error of network always occuring. And sometimes it works while sometimes not worl, I want to know the reason to cause it. The warning message is:

**Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : 
  cannot open URL'http://maps.googleapis.com/maps/api/staticmap?center=27.959375,121.920875&zoom=8&size=640x640&scale=2&maptype=terrain&sensor=false'
Warning message:
In download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :
  cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=27.959375,121.920875&zoom=8&size=640x640&scale=2&maptype=terrain&sensor=false': HTTP status was '404 Not Found'**

My code was:

library(ggplot2)
library(ggmap) 
mapImageData<-get_googlemap(center=c(lon=mean(dat$Lon),lat=mean(dat$Lat)),zoom=8,maptype='terrain',color='bw')

And dat was my dataset of a station map, the head of it was:

Season  Lon Lat 
Spring  120.93  27 
Spring  121.18  27 
Spring  121.43  27 
Spring  121.6   27.25 
Spring  121.35  27.25 
Spring  121.5   27.5

This is a whole different story. Static maps is a service that does not require any javascript. You simply call an url, and Google will return a maps image, making it possible to insert the URL directly into your tag. The newest version is version 2, and this requires a key to function because a usage limit is applied.

A key can be requested here: https://code.google.com/apis/console

And the key should be added to the request for the correct image to be generated:

http://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&zoom=13&size=600x300&key=API_console_key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM