2017-08-07 198 views
0

下面的代碼使用Google API來查找兩個位置之間的距離,在運行代碼時,它給出瞭如下所示的錯誤,請建議如何解決此錯誤。如何解決錯誤「AttValue:」或預期?

> gmapsdistance(origin = "PAWTUCKET+LOWELL+MA", destination = 
"INDUSTRIAL WAY+SALEM+NH", combinations = "all", mode = "driving", key 
= "My_key") 

Error:
1: AttValue: " or ' expected 2: attributes construct error 3: Couldn't find end of Start Tag html line 2 4: Extra content at the end of the document

+0

請參閱下面的解決方案,讓我知道如果你有任何問題。如果這可以爲​​您解決問題,請點擊複選標記,讓未來的讀者知道有一個解決方案。 –

回答

-1

有使用的空間我googleway包沒有問題

library(googleway) 

apiKey <- 'your_api_key' 

google_distance(origins = list("PAWTUCKET+LOWELL+MA"), 
       destinations = list("INDUSTRIAL WAY+SALEM+NH"), 
       mode = "driving", 
       key = apiKey) 

# $destination_addresses 
# [1] "Industrial Way, Salem, NH 03079, USA" 
# 
# $origin_addresses 
# [1] "Pawtucket Blvd, Lowell, MA 01854, USA" 
# 
# $rows 
# elements 
# 1 23.2 km, 23150, 27 mins, 1648, 27 mins, 1605, OK 
# 
# $status 
# [1] "OK" 

說了這麼多,和哈克-R在他們的回答提到了,因爲你必須在一個空間出現實際錯誤的destination(「INDUSTRIAL WAY + SALEM + NH」)。將其替換爲+,它將起作用。

gmapsdistance(origin = "PAWTUCKET+LOWELL+MA", 
       destination = "INDUSTRIAL+WAY+SALEM+NH", 
       combinations = "all", 
       mode = "driving", 
       key = 'api_key') 

$Time 
[1] 1591 

$Distance 
[1] 23150 

$Status 
[1] "OK" 

從文檔?gmapsdistance

If more than one word for a same location is used, they should be separated by a plus sign e.g. "Bogota+Colombia"

實際的錯誤來源於XML包,其發動機罩下使用的gmapsdistance

+0

你不需要API密鑰。解決方案的其餘部分在8小時前回答了我的答案。 –

+0

@ Hack-R我的文章的目的是爲了突出特定的錯誤(我相信您在編輯之前的原始答案有點誤導),並突出顯示了獲得解決方案的另一種方法。我已在我的帖子中編輯和記入您。而且,不是我投票給你的。 – SymbolixAU

1

我覺得你的目的地是缺少+我證實,這作品時,語法和精度修正

證明:。

gmapsdistance(origin = "100+PAWTUCKET+ST+LOWELL+MA", 
       destination = "INDUSTRIAL+WAY+SALEM+NH", 
       mode = "driving") 
$Time 
[1] 1506 

$Distance 
[1] 19223 

$Status 
[1] "OK" 

順便說一句,你並不需要爲這個API密鑰。

+0

問題在於缺少'+';谷歌沒有找到指定的地址 – SymbolixAU

+0

@SymbolixAU嗯,它在我的實驗中做到了,但是無論哪種方式,我認爲你會同意我找到了解決方案 –