以下代码使用Google API查找两个位置之间的距离。在运行代码时,它给出了如下所示的错误。请建议如何解决此错误。
> gmapsdistance(origin = "PAWTUCKET+LOWELL+MA", destination =
"INDUSTRIAL WAY+SALEM+NH", combinations = "all", mode = "driving", key
= "My_key")
错误:
1:AttValue:“或'预期 2:属性构造错误 3:无法找到开始标记html第2行的结尾 4:文档末尾的额外内容
答案 0 :(得分:1)
我认为您错过了目的地中的gmapsdistance(origin = "100+PAWTUCKET+ST+LOWELL+MA",
destination = "INDUSTRIAL+WAY+SALEM+NH",
mode = "driving")
。我在验证语法和精度得到纠正后验证了这一点。
<强>证明:强>
$Time
[1] 1506
$Distance
[1] 19223
$Status
[1] "OK"
order
顺便说一句,您不需要API密钥。
答案 1 :(得分:-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"
话虽如此,正如Hack-R在他们的回答中提到的那样,你的实际错误是因为你的destination
(&#34; INDUSTRIAL WAY + SALEM + NH&#34;)中有空格。将其替换为+
即可。
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
如果使用同一位置的多个单词,则应使用加号分隔,例如&#34;波哥大+哥伦比亚&#34;
实际错误来自XML
包,由gmapsdistance
引用。