我想在河包ggmap
與功能geocode
工作,但我不能運行R文件中的代碼示例:錯誤fromJSON:意外的字符
geocode("houston texas", output = "more")
,其結果是:
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=houston%20texas&sensor=false
Error in fromJSON(paste(lines, collapse = "")) : unexpected character '<'
我不知道它是與fromJSON
的問題,所以我下載了JSON文件(如abcd.json),然後將其導入R:
data <- fromJSON(file="abcd.json")
它的工作原理。
但是當我做:
theurl <- "http://maps.googleapis.com/maps/api/geocode/json?address=houston%20texas&sensor=false"
data <- fromJSON(file=theurl)
它返回相同的錯誤:
Error in fromJSON(paste(lines, collapse = "")) : unexpected character '<'
我Rcurl
都嘗試rjson
和RJSONIO
在一起。它以任何方式返回錯誤。
相關信息:
- RStudio版本1.0.143;
- R版本3.4.0
- macOS Sierra 10.12.6
- 位置:北京。 (可能有一些做互聯網禁止谷歌地圖API的。)
和你的'geocode()'函數對我來說不會出錯。也許你可以試試'library(googleway); google_geocode(「houston texas」,key =「」)' – SymbolixAU
@SymbolixAU他們使用'rjson'實現,它使用'file'而不是'text':https://www.rdocumentation.org/packages/ rjson/versions/0.2.15/topics/fromJSON – miken32
@ miken32 - 啊是 - 好點。 – SymbolixAU