使用Google_distance r函数量化距离

lmyy7pcs  于 2023-01-03  发布在  Go
关注(0)|答案(1)|浏览(109)

我尝试使用Google_distance r函数来量化地点之间的距离。我已经运行了Google_distance函数的示例,但地点之间的距离缺失。其他字段完整,但距离不完整。
我已经激活了距离API从谷歌.
代码为:

key <- "your key here"
set_key(key = key, api = "distance")
google_keys()

df <- google_distance(origins = list(c("Melbourne Airport, Australia"),
                                     c("MCG, Melbourne, Australia"),
                                     c(-37.81659, 144.9841)),
                      destinations = c("Portsea, Melbourne, Australia"),
                      key = key) 

head(df)

$destination_addresses
\[1\] "Portsea VIC 3944, Australia"

$origin_addresses
\[1\] "Melbourne Orlando International Airport (MLB), 1 Air Terminal Pkwy, Melbourne, FL 32901, USA"
\[2\] "Brunton Ave, Richmond VIC 3002, Australia"  
\[3\] "Jolimont, Wellington Cres, East Melbourne VIC 3002, Australia"

$rows
\*\*\* Empty \*\*\*
$status
\[1\] "OK"

也许,我需要打开其他谷歌API,但我不知道是哪些。你有什么想法,我可以解决这个问题?
欢迎提出任何建议和改进,非常感谢

bd1hkmkf

bd1hkmkf1#

问题可能出在您的API或设置中。您确定您选择了正确的API或设置吗?默认代码对我有效,并按预期返回行。我使用的是Distance Matrix API

df <- google_distance(origins = list(c("Melbourne Airport, Australia"),
                                     c("MCG, Melbourne, Australia"),
                                     c(-37.81659, 144.9841)),
                      destinations = c("Portsea, Melbourne, Australia"),
                      key = key) 

head(df)

$destination_addresses
[1] "Portsea VIC 3944, Australia"

$origin_addresses
[1] "Melbourne Airport (MEL), Melbourne Airport VIC 3045, Australia" "Brunton Ave, Richmond VIC 3002, Australia"                     
[3] "Jolimont, Wellington Cres, East Melbourne VIC 3002, Australia" 

$rows
                                  elements
1 133 km, 133291, 1 hour 41 mins, 6043, OK
2 108 km, 107702, 1 hour 24 mins, 5018, OK
3 108 km, 108451, 1 hour 25 mins, 5074, OK

$status
[1] "OK"

相关问题