想知道是否有人可以幫助我。我試圖返回一個地址的lat和lng的結果。新的編碼和卡住了。下面的代碼工作正常,直到地理編碼從v2到v3。你能告訴我我要去哪裏嗎?我是否需要一個新的v3密鑰或密鑰?提前致謝。如何在經典ASP中使用Geocoding API v3
<%
Function GetXML(url)
Dim xmlobj
Set xmlobj = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xmlobj.setTimeouts 30000, 30000, 30000, 30000
xmlobj.Open "GET", url, False
xmlobj.send()
If xmlobj.status = 200 Then
GetXML = xmlobj.responseXML.xml
Else
Response.Write "The geocoding server could not be reached."
Response.End
End If
End Function
address = "30 Dixon, EN76HA"
url="http://maps.google.com/maps/geo?output=xml&key=XXXXXXX &q="&Server.URLEncode(address)
Response.Write "You entered: "&address&"<br />"
xml = GetXML(url) 'Function to return raw XML as text
if InStr(xml,"<coordinates>")>0 then
coords = split(xml,"<coordinates>") 'Get everything after the opening coordinates tag
coords2 = split(coords(1),"</coordinates>") 'Get everything before the ending coordinates tag
coordinatesSplit = split(coords2(0),",") 'split it at the commas
lng = coordinatesSplit(0) 'The first value is the longitude
lat = coordinatesSplit(1) 'The second value is the latitude
Response.Write "The geo-coded coordinates are: "&lat&" "&lng
else
'No coordinates were returned
Response.Write "The address could not be geocoded."
Response.End
end if
%>
您是否收到錯誤?你看到了什麼輸出? –
對不起。我收到:無法聯繫到地理編碼服務器。我認爲這與URL =「XXX」有關,但還沒有弄清楚。 – user3465723