2016-01-14 54 views
4

我想从Google地图中检索搜索词的位置。从Google地图中检索位置坐标R

Here's an example with the term "pizza" near London

我想获得纬度和经度的结果的每一个地方。我一直在寻找,这是可能的,如果你有地址。

Here's an example using address.

不过,我很感兴趣,使用搜索项,就像当你搜索在谷歌地图的一个术语,你会怎么做。

+1

[Google Places API](https://developers.google.com/places/web-service/search)可以为您提供所需的信息,但您需要编写脚本以便从R中调用它'httr'和/或'jsonlite'将会很有用。 – alistaire

+0

@alistaire如果我遇到困难,我会查看它并回来 –

回答

4

我按照评论中的建议去Google Places API。 我设法创建一个帐户并获得一个密钥。 我写了一个名为encontrar的函数,该函数基本上搜索中心半径为关键字的地方。 我为了得到中心我去了谷歌地图,发现了这一点的经度和纬度。手工操作非常快,我认为我不需要为此编写代码,但是成为我的客人。 所以一旦中心定义,

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"帮助。在其他情况下应该改变。

+0

确定此作品,但仅限于20 ...正在寻找解决方法 –

+0

一种“解决方法”是向Google支付费用。 –

+0

嗯,是的,这将是真棒,但不是我正在寻找的解决方法。也许我可以在城市内采样,并使用您每天获得的1000个免费查询,直到独特地点的数量收敛,但只是想法 –

相关问题