2013-06-25 143 views
0

我想請求,並保存在DDBB的緯度和經度從谷歌地圖的XML從谷歌XML/LNG asp代碼,我正在使用的代碼如下:用於獲取經緯度

  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」) 中,它表示它不是一種方法。 任何見解?先謝謝了。

回答

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