I am trying to get the coordinates of businesses by their name. I have reviewed several questions on using 'geocode' but they all seem to work based on the address. See below two examples trying to get the coordinates of The Westbury Hotel London:
library(ggmap)
geocode("London")
geocode("The Westbury Hotel London") # Returns coordinates of Westbury Road in London
A more complex approach:
require(RJSONIO)
library(ggmap)
geocodeAddress <- function(address) {
require(RJSONIO)
url <- "http://maps.google.com/maps/api/geocode/json?address="
url <- URLencode(paste(url, address, "&sensor=false", sep = ""))
x <- fromJSON(url, simplify = FALSE)
if (x$status == "OK") {
out <- c(x$results[[1]]$geometry$location$lng,
x$results[[1]]$geometry$location$lat)
} else {
out <- NA
}
Sys.sleep(0.2) # API only allows 5 requests per second
out
}
geocodeAddress("The Westbury Hotel London") # Returns London coordinates
Other questions mentioned that it is possible to get coordinates from places with 'geocode' but, at least in my case, it is not working. Any idea on how to get coordinates by business name from google maps hugely appreciated.