Link to home
Create AccountLog in
Avatar of Nico2011
Nico2011Flag for United Kingdom of Great Britain and Northern Ireland

asked on

XML Google Map Issue

Hello,

I am trying to get the lng/lat data from Google maps using the following code, however, I simply get a blank page and cannot even look at the source code, which is bizarre.

My Code is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="deps/db.asp"-->

<%
server.ScriptTimeout = 1200
SQL = SQL & "select * from locations where lng = '' OR lng = NULL order by Region" 
Set RS = DB.Execute(SQL)

While NOT RS.EOF
ID = RS("ID")

  address = RS("location") & "," & RS("Region") & "," & RS("Country")

  Set objSrvHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
  Set objXMLSend = Server.CreateObject("Msxml2.DOMDocument.6.0")
  Set objXMLReceive = Server.CreateObject("Msxml2.DOMDocument.6.0")

   objXMLSend.async = false
   objXMLSend.loadXML ("*")
   
   url = "http://maps.google.com/maps/api/geocode/xml?address="
   sensor = "&sensor=false"
   url = url & address & sensor
   
   objSrvHTTP.open "GET", url, false
   objSrvHTTP.send (objXMLSend)
   Set objXML = objSrvHTTP.responseXML
   Response.ContentType = "text/xml"
   
   If objXML.parseError.errorCode <> 0 Then
	 msg = "Error Found"
   End If

 Set objLst = objXML.getElementsByTagName("*")

j = 0
i = 0
AddressStr = ""
AddStrLinkBack = ""

 For i = 0 to (objLst.length - 1)
	If objLst.item(i).nodeName = "lat" then
	lat = objLst.item(i).text
	end if
	If objLst.item(i).nodeName = "lng" then
	lng = objLst.item(i).text
	end if
    If objLst.item(i).nodeName = "formatted_address" Then
      AddressStr = objLst.item(i).text
	  j = j + 1
	  url = "searchaddress.asp?address=" & objLst.item(i).text
	  AddStrLinkBack = AddStrLinkBack & "<p><a href=""" & url & """>" & objLst.item(i).text & " lng: " & lng & " lat: " & lat & "</a></p>"
    End If
 Next

If j = 1 then
SQL = "Update Locations set NotFound=0 where ID='" & ID & "'"
else
SQL = "Update Locations set NotFound=1 where ID='" & ID & "'"
End if
msg = msg & SQL & "<BR>"
'DB.Execute(SQL)

Set objSrvHTTP = Nothing
Set objXMLSend = Nothing
Set objXMLReceive = Nothing
Set objXML = Nothing

RS.MoveNext
Wend

RS.Close
Set RS = Nothing
DB.Close
Set DB = Nothing
%>

Open in new window


Thanks in advance for your help!
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

There are a number of issues, I tried to fix some and hope you can pick it back up from here. If you have specific questions as to why I did some changes, ask away!
<%@LANGUAGE="VBSCRIPT"%><%
Option Explicit

Server.ScriptTimeout = 1200

Dim SQL, RS, ID, address, objSrvHTTP, url, sensor, objXML, objLst, j, i, AddressStr, AddStrLinkBack, lat, lng, msg ' , objXMLSend, objXMLReceive
%><?xml version="1.0" encoding="ISO-8859-1"?>
<!--#include file="deps/db.asp"-->
<%
SQL = SQL & "select * from locations where lng = '' OR lng is NULL order by Region" 
Set RS = DB.Execute(SQL)

Response.Write "<locations>"
While NOT RS.EOF
	Response.Write "<location>"
	ID = RS("ID")
	Response.Write "<id>" & ID & "</id>"

  address = RS("location") & "," & RS("Region") & "," & RS("Country")

  Set objSrvHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
  'Set objXMLSend = Server.CreateObject("Msxml2.DOMDocument.6.0")
  'Set objXMLReceive = Server.CreateObject("Msxml2.DOMDocument.6.0")

   'objXMLSend.async = false
   'objXMLSend.loadXML ("*")
   
   url = "http://maps.google.com/maps/api/geocode/xml?address="
   sensor = "&sensor=false"
   url = url & Server.URLEncode(address) & sensor

	Response.Write "<url>" & Server.HTMLEncode(url) & "</url>"
   
   objSrvHTTP.open "GET", url, false
   objSrvHTTP.send '(objXMLSend)
   Set objXML = objSrvHTTP.responseXML
   Response.ContentType = "text/xml"
   
   If objXML.parseError.errorCode <> 0 Then
	 msg = "Error Found"
   Else

	Response.Write "<receivedxml>" & Server.HTMLEncode(objXML.xml) & "</receivedxml>"

	j = 0
	i = 0
	AddressStr = ""
	AddStrLinkBack = ""

	Set objLst = objXML.selectNodes("//formatted_address")
	For i = 0 to (objLst.length - 1)
		If objLst.item(i).nodeName = "formatted_address" Then
		  AddressStr = objLst.item(i).text
		  j = j + 1
		  url = "searchaddress.asp?address=" & objLst.item(i).text
		  AddStrLinkBack = AddStrLinkBack & "<p><a href=""" & url & """>" & objLst.item(i).text & " lng: " & lng & " lat: " & lat & "</a></p>"
		End If
	Next
	Set objLst = Nothing

	Set objLst = objXML.selectNodes("//location/*")
	For i = 0 to (objLst.length - 1)
		Response.Write "<test_" & objLst.item(i).nodeName & ">item " & i & ": " & objLst.item(i).text & "</test_" & objLst.item(i).nodeName & ">"
		If objLst.item(i).nodeName = "lat" then
			lat = objLst.item(i).text
		end if
		If objLst.item(i).nodeName = "lng" then
			lng = objLst.item(i).text
		end if
	Next
	Set objLst = Nothing

	Response.Write "<link>" & Server.HTMLEncode(AddStrLinkBack) & "</link>"

	If j = 1 then
		SQL = "Update Locations set NotFound=0 where ID='" & ID & "'"
	else
		SQL = "Update Locations set NotFound=1 where ID='" & ID & "'"
	End if
	msg = msg & SQL & "<BR>"
	Response.Write "<msg>" & Server.HTMLEncode(msg) & "</msg>"
	'DB.Execute(SQL)

   End If

	Set objSrvHTTP = Nothing
	'Set objXMLSend = Nothing
	'Set objXMLReceive = Nothing
	Set objXML = Nothing

	Response.Write "</location>"
	RS.MoveNext
Wend
Response.Write "</locations>"

RS.Close
Set RS = Nothing
DB.Close
Set DB = Nothing
%>

Open in new window

Avatar of Nico2011

ASKER

Thanks Robert, but it still doesn't give anything - not even the response.write (s) work...  All I get is a blank page that I cannot see the source code of!  The page can be seen here: http://www.villasdirect.com/test.asp
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Brilliant Robert - works great now - thank you!

FYI IE wouldn't show me the source, but Chrome did, and showed me that there was a second variable that wasn't declared.

Thanks again - really appreciated!
Hi Robert,

Just posting another question in relation to this one - perhaps it'll be easy for you to answer...?

Best wishes/Nico