Mat*_*ina 4 google-maps r google-maps-api-3
我想从Google地图中检索搜索词的位置。
我想获得每个地方的经度和纬度结果。我一直在搜索,如果您有地址,这是可能的。
但是,我对使用搜索字词感兴趣,就像在Google Maps中搜索字词一样。
我按照注释中的建议去了Google Places API。我设法创建了一个帐户并获得了一把钥匙。我写了一个名为的函数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")
Run Code Online (Sandbox Code Playgroud)
给出一个很好的数据框,其位置在500m
同样值得一提的是"&types=food|restaurant"这种情况下的帮助,因为关键字是“ pizzeria”。在其他情况下,应进行更改。