1

I would like to draw a map of Hong Kong basemap using R but it failed. Below is the code and the error R returns:

library(ggmap)
library(ggplot2)

map <- get_map(location = "Hong Kong", zoom = 10, scale = 2, maptype = "roadmap", 
               source = "google", force = ifelse(source == "google", TRUE, TRUE), 
               messaging = FALSE, urlonly = FALSE, filename = "ggmapTemp", 
               crop = TRUE, color = "color", language = "en-EN", api_key)

Error in data.frame(ll.lat = ll[1], ll.lon = ll[2], ur.lat = ur[1], ur.lon = ur[2]) : arguments imply differing number of rows: 0, 1 In addition: Warning message: geocode failed with status OVER_QUERY_LIMIT, location = "Hong Kong"

The above coding is fine for taiwan, china and state, don't know why it failed for Hong Kong.

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
  • have you tried other cities like Beijing, Rome or New York? – Roman Apr 05 '18 at 14:32
  • I am failing to replicate this error. The output: https://i.stack.imgur.com/9Trwj.png – Michael Harper Apr 05 '18 at 14:38
  • Is that the full error message or do you get: `Error in data.frame(ll.lat = ll[1], ll.lon = ll[2], ur.lat = ur[1], ur.lon = ur[2]) : arguments imply differing number of rows: 0, 1 In addition: Warning message: geocode failed with status OVER_QUERY_LIMIT, location = "Hong Kong" `. Normally this error occurs when you are over the query limit for the Google Maps API – Michael Harper Apr 05 '18 at 14:44
  • @Jimbou yes, and failed as well.... – Annabelle Mak Apr 05 '18 at 14:56
  • @MikeyHarper May I know how did you get the output? ; yes I got the over query limit as well – Annabelle Mak Apr 05 '18 at 14:59
  • It worked fine for me. I haven't used `ggmap` in a few months so I am far from the query limit. – mysteRious Apr 05 '18 at 15:04
  • 1
    Possible duplicate of [Getting OVER QUERY LIMIT after one request with geocode](https://stackoverflow.com/questions/36175529/getting-over-query-limit-after-one-request-with-geocode) – Michael Harper Apr 05 '18 at 15:05
  • The key issue here is the `OVER_QUERY_LIMIT`, which the question above should help explain. – Michael Harper Apr 05 '18 at 15:08
  • I checked with geocodeQueryCheck() as stated in https://stackoverflow.com/questions/36175529/getting-over-query-limit-after-one-request-with-geocode and it returns there are 2467 geocoding queries remaining – Annabelle Mak Apr 05 '18 at 15:18
  • While the results for city names keeps failing, it worked everytime when i changed the location to a country name. – Annabelle Mak Apr 05 '18 at 15:26

1 Answers1

1

As of October 2018, getmap() only works with a registered and billing-activated Google Maps API key and longitude / latitude coordinates.

See more info and a step-by-step tutorial here.

Roman
  • 4,744
  • 2
  • 16
  • 58