用于从谷歌XML获取lat / lng的Asp代码

时间:2013-06-25 09:43:35

标签: xml google-maps-api-3 asp-classic

我正在尝试从谷歌地图xml请求并保存在DDBB中的lat和lng,我正在使用的代码如下:

            url = "http://maps.googleapis.com/maps/api/geocode/xml?address="&sensor=false"
            response.write "URL... : " & url &"</br>"
            Set objXMLDoc = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
            objXMLDoc.setTimeouts 30000, 30000, 30000, 30000
            objXMLDoc.Open "GET", url, False
            objXMLDoc.send()

            Dim xmlLocation 

            For Each xmlLocation In objXMLDoc.documentElement.selectNodes("location")
                 lat = xmlLocation.selectSingleNode("lat").text   
                 lng = xmlLocation.selectSingleNode("lng").text   
                 Response.Write Server.HTMLEncode(lat) & " "
                 Response.Write Server.HTMLEncode(lng) & "<br>"   
            Next

我一直收到错误:                    对于每个xmlLocation在objXMLDoc.documentElement.selectNodes(“location”)中    ,它说它不是一种方法。 任何见解?谢谢你提前。

1 个答案:

答案 0 :(得分:2)

你必须使用objXMLDoc.responsexml而不是objXMLDoc

像这样:

response.write "<hr>"

response.write objXMLDoc.responsexml.selectSingleNode("GeocodeResponse/result/geometry/location/lat").text

response.write "<hr>"

response.write objXMLDoc.responsexml.selectSingleNode("GeocodeResponse/result/geometry/location/lng").text