Is there an R package to access the google places

2019-06-14 07:33发布

I'm currently using Rselenium to input doctors' names into Google Maps, and then collect the addresses associated with those names. For example, if I input "Susan Marra" my current program would return "11782 Sand Point Way NE, Seattle, WA 98125", the address of her practice.

This worked fine originally, but the number of addresses has now made it prohibitively slow(I need to give maps half a second to load after I input the name). Is there a way to do the same thing more quickly using the API and ggmaps, or another R package?

I've looked through the documentation for a couple of Google Maps related packages and haven't found anything with that functionality.

1条回答
仙女界的扛把子
2楼-- · 2019-06-14 08:18

With ggmap you can get both the lat/lon from an address using geocode(), or the address from a lat/lon using revgeocode().

geocode() is pretty much like searching for a place in google maps. If you don't know the exact address, you can give it a search string and it will try and find it for you.

library(ggmap)

## get lat/lon from address    
add <- c("Whitehouse, DC", "Flinders Street Station, Melbourne")

g <- geocode(add)
g
        lon       lat
1 -77.03673  38.89761
2 144.96706 -37.81827

## get address from lat/lon
## revgeocode(location = c(lon, lat))
apply(g, 1, function(x) revgeocode(location = c(x["lon"], x["lat"])))
[1] "The White House, 1600 Pennsylvania Ave NW, Washington, DC 20500, USA"
[2] "Melbourne VIC 3000, Australia"
查看更多
登录 后发表回答