TransWikia.com

Plotting Points in R with Google Map context. Error in download.file(urlStr, destfile, mode = "wb", quiet = TRUE)

Geographic Information Systems Asked by bobbynaira on January 11, 2021

I am trying to plot point data with Google Map context but i keep getting an Error. I tried the same using OSM context and it worked just fine.

R Code below

library(RgoogleMaps)
Lat <- as.vector(quakes$lat)
Long <- as.vector(quakes$long)
MyMap <- MapBackground(lat=Lat, lon=Long, zoom = 10)
PlotOnStaticMap(MyMap,Lat,Long,cex=tmp+0.3,pch=1,
                col= '#FB6A4A80')

Error Report

"https://maps.googleapis.com/maps/api/staticmap?center=-24.655,176.9&zoom=4&size=640x640&maptype=mobile&format=png32&sensor=true&key="
Error in download.file(urlStr, destfile, mode = "wb", quiet = TRUE) : 
  cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=-24.655,176.9&zoom=4&size=640x640&maptype=mobile&format=png32&sensor=true&key='
In addition: Warning message:
In download.file(urlStr, destfile, mode = "wb", quiet = TRUE) :
  cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=-24.655,176.9&zoom=4&size=640x640&maptype=mobile&format=png32&sensor=true&key=': HTTP status was '403 Forbidden'

One Answer

Note the:

   HTTP status was '403 Forbidden'

which makes me think you need an API key - google have recently changed their policy on this. Go get one, and then try:

 MyMap <- MapBackground(lat=Lat, lon=Long, zoom = 10, API_console_key="my-api-key-here-XXXXX")

Don't show your key in public code.

Answered by Spacedman on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP