使用此google_distance函数时,我无法理解输出。在ggmap中使用mydist()时,我会得到从A点到B点所需的里程数,分钟数,小时数。
现在,当我使用google_distance时,我的输出看起来像这样。任何人都可以帮忙解释每个数字的含义吗?
$rows
elements
1 791 km, 790588, 7 hours 28 mins, 26859, 7 hours 35 mins, 27286, OK
我的代码如下:
results <- google_distance(origins = list(c(26.19660, -98.23591)),
destinations = list(c(31.62327, -94.64276)),
mode = "driving", key = key, simplify = TRUE)
答案 0 :(得分:3)
您看到的是standard JSON response,但已简化为data.frame(根据simplify = TRUE
参数)
如果你在答案中看得更深一层,你就会得到那些缬草的描述
results$rows$elements
# [[1]]
# distance.text distance.value duration.text duration.value duration_in_traffic.text duration_in_traffic.value
# 1 791 km 790588 7 hours 28 mins 26859 7 hours 28 mins 26906
其中
distance.value
以米为单位duration.value
在几秒钟内同样,查看result
对象的结构,您将看到所有JSON元素
str(results)
# List of 4
# $ destination_addresses: chr "805 E College St, Nacogdoches, TX, USA"
# $ origin_addresses : chr "1400-1498 W Houston Ave, McAllen, TX 78501, USA"
# $ rows :'data.frame': 1 obs. of 1 variable:
# ..$ elements:List of 1
# .. ..$ :'data.frame': 1 obs. of 4 variables:
# .. .. ..$ distance :'data.frame': 1 obs. of 2 variables:
# .. .. .. ..$ text : chr "791 km"
# .. .. .. ..$ value: int 790588
# .. .. ..$ duration :'data.frame': 1 obs. of 2 variables:
# .. .. .. ..$ text : chr "7 hours 28 mins"
# .. .. .. ..$ value: int 26859
# .. .. ..$ duration_in_traffic:'data.frame': 1 obs. of 2 variables:
# .. .. .. ..$ text : chr "7 hours 28 mins"
# .. .. .. ..$ value: int 26906
# .. .. ..$ status : chr "OK"
# $ status : chr "OK"
进一步参考: