2016-01-14 58 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個免費查詢,直到獨特地點的數量收斂,但只是想法 –

相關問題