Get location coordinates from Google maps in R

I want to get the location of a search term with Google Maps.

Here is an example with the term "pizza" near London

I would like to get latitude and longitude results for each place. I searched, and this is possible if you have an address.

Here is an example of using an address.

However, I am interested in using the search query in the same way as if you were doing a search on Google Maps.

+4
source share
1 answer

API Google , . . encontrar, . , Google . . , , . , ,

coordenadas<-c(-34.605424, -58.458499)

encontrar<-function(lugar,radius,keyword){

# radius in meters
#lugar is coordinates from google maps by hand
  coor<-paste(lugar[1],lugar[2],sep=",")
  baseurl<-"https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
  google_key<-c(" YOUR KEY HERE")


q<-paste(baseurl,"location=",coor,"&radius=",radius,"&types=food|restaurant&keyword=",keyword,"&key=",google_key, sep="")

print(q)

data1<-fromJSON(q)

lat_long<-data.frame(lat=data1$results$geometry$location$lat,long=data1$results$geometry$location$lng)

#print(data1)

sitios<-data1$results$name

df<-cbind(sitios,lat_long)
return(df)
}


encontrar(lugar = coordenadas,radius = 500,"pizzeria")

500

, "&types=food|restaurant" , "". .

+5

Source: https://habr.com/ru/post/1624351/


All Articles