2017-08-07 202 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嗯,它在我的实验中做到了,但是无论哪种方式,我认为你会同意我找到了解决方案 –