Google表格无法解析与Google Distance Matrix API的“距离”

问题描述 投票:0回答:1

我使用Google表格作为里程跟踪器来计算从我家到各个地址的距离。这个公式已经为我工作了几个月,但最近停止了:

=ROUND((importxml("https://maps.googleapis.com/maps/api/distancematrix/xml?&origins="&"My+Home+Address"&"&destinations="&A1&"&sensor=false&units=imperial&alternatives=false&key=MY_API_KEY","/DistanceMatrixResponse/row/element/distance/value")/1609.344)*2,1)

我正在使用我自己的有效API密钥,并已验证该查询在Google表格之外可以正常工作。有趣的是,如果我将“ / distance / value”更改为“ / duration / value”,Sheets会返回正确的响应。

这是返回的距离矩阵的XML外观:

<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Home Address, USA</origin_address>
<destination_address>Destination Address, USA</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>1983</value>
<text>33 mins</text>
</duration>
<distance>
<value>29971</value>
<text>18.6 mi</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>

如何获得“距离”以重新工作?

google-sheets google-distancematrix-api google-sheets-importxml
1个回答
0
投票

这对我有用:

=IMPORTXML("https://maps.googleapis.com/maps/api/distancematrix/xml?&origins="&B1&"&destinations="&B2&"&sensor=false&alternatives=false&key="&B3,"/DistanceMatrixResponse/row/element/distance/text")

顺便说一句,如果您摆脱了units=imperial,则默认为公制,而您不必/1609.344

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.