我試圖用谷歌地圖API定義2點之間的駕駛距離。它返回一個我加載到XMLDOM對象中的XML。然而,我似乎無法找到任何地方,我可以如何獲得兒童內兒童的價值......我已閱讀微軟教程,但並未顯示如何從XML中檢索值。經典的ASP讀取XML值
一個例子XML是:
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Gentsesteenweg 5, 9200 Dendermonde, België</origin_address>
<destination_address>Veerstraat 39, 9200 Dendermonde, België</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>117</value>
<text>2 min.</text>
</duration>
<distance>
<value>1061</value>
<text>1,1 km</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>
我的代碼的部分是:
Set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")
strURL = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & dblFromLatitude & "+" & dblFromLongitude & "&destinations=" & dblToLatitude & "+" & dblToLongitude & "&mode=driving&language=" & strLanguage & "&sensor=false"
'DebugFile strURL
XmlObj.Open "POST", strURL, false
XmlObj.send
strResponse = XmlObj.responseText
Set XmlObj = Nothing
Set xmlLongLat = Server.CreateObject("Microsoft.XMLDOM")
xmlLongLat.async=false
xmlLongLat.loadXML(strResponse)
If Not xmlLongLat.GetElementsByTagName("DistanceMatrixResponse")(0).ChildNodes(0).GetElementsByTagName("row")(0).ChildNodes(0).GetElementsByTagName("element")(0).ChildNodes(0).GetElementsByTagName("distance")(0).ChildNodes(0) Is Nothing Then
dblDrivingDistance = Round(CDbl(Nz(xxmlLongLat.GetElementsByTagName("DistanceMatrixResponse")(0).ChildNodes(0).GetElementsByTagName("row")(0).ChildNodes(0).GetElementsByTagName("element")(0).ChildNodes(0).GetElementsByTagName("distance")(0).ChildNodes(0).NodeValue, 0))/1000,2)
Else 'xmlLongLat.GetElementsByTagName("element")(0) Is Nothing Then
dblDrivingDistance = 0
DebugFile "fgfzefzef"
End If 'xmlLongLat.GetElementsByTagName("element")(0) Is Nothing Then
Set xmlLongLat = Nothing
我想要得到的「價值」的「距離」,但我不覺得是公正儘管嘗試過一切
您是否已經嘗試過「分步」方法?爲什麼不把響應存儲到變量中? – reporter