lboeldt
Posts: 53
|
Posted: 06/27/2010, 9:58 AM |
|
Yahoo Location finder geocodes address information and returns longitude and latitude. It also nicely fills in the blanks if all you have is partial information. This is very handy for falidating form information and getting your address list ready for mapping. You need to acquire a Yahoo APPID and paste it into this app (instructions in the class).
I also have a quick and dirty CSS application that uses this class in a form. I'll upload if possible. Otherwise message me, I'll figure out a way to get it online.
'' YGeoCoder class
'' by Larry Boeldt
'' (C) 2010 Larry Boeldt
''
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Class: YGeoCoder Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Properties(s):
'
'
' Methods:
' Geocode( address, city, state, zip )
'
' Description:
' A class that wraps most of the functionality of yahoo geocoder.
'
' Setup Instructions:
' Get your appid here: https://developer.apps.yahoo.com/wsregapp/
' Copy and paste the licence code in the appid="" assignment
' in class_initialize.
'***************************************************************************
class YGeoCoder
private appid
private m_street
private m_city
private m_state
private m_zip
private m_lon
private m_lat
private m_precision
private m_country
private m_xml
private m_reason
private m_output
private m_url
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Function: class_initialize Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Parameter(s):
' none
'
' Return Value:
' none
'
' Description:
' Initialize the class object with default values.
' Remember to sign up for your yahooappid and paste it below
'***************************************************************************
sub class_initialize()
'' Get your appid here: https://developer.apps.yahoo.com/wsregapp/
'' copy and paste your app id below
appid=""
m_output = "xml"
end sub
property get output()
output = m_output
end property
property get url()
url = m_url
end property
property let output(value)
if value="php" or value="xml" then
m_output=value
else
m_output = "xml"
end if
end property
property get lon()
lon = m_lon
end property
property get lat()
lat = m_lat
end property
property get city()
city = m_city
end property
property get state()
state = m_state
end property
property get zip()
zip = m_zip
end property
property get country()
country = m_country
end property
property get precision()
precision = m_precision
end property
property get address()
address=m_street
end property
property get street()
street = m_street
end property
property get xml()
xml = m_xml
end property
property get reason()
reason = m_reason
end property
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Function: GetPrecision Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Parameter(s):
' Doc XML Document from Yahoo
'
' Return Value:
' Precision value from yahoo
'
' Description:
' Get the precision value returned by yahoo
'
'***************************************************************************
function GetPrecision( doc )
Dim node
dim value
set node=doc.documentElement.selectSingleNode( "/ResultSet/Result" )
if node is nothing then
value = "none"
else
value = node.GetAttribute( "precision" )
end if
set node = nothing
GetPrecision = value
end function
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Function: GetXMLValue Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Parameter(s):
' Doc XML Document from Yahoo
' name the tag name/value you want to retrieve
' Return Value:
' Value of specified tag or blank string
'
' Description:
' Get one of the address return values from the yahoo XML
'
'***************************************************************************
function GetXMLValue( doc, name )
Dim node
dim value
set node=doc.documentElement.selectSingleNode("/ResultSet/Result/" & name )
if node is nothing then
value = ""
else
value = node.text
end if
set node = nothing
GetXMLValue = value
end function
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Function: Geocode Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Parameter(s):
' street street address to geocode
' city city name to geocode
' state state to geoocde
' zip zip code/postal code to geocode
'
' Return Value:
' none
'
' Description:
' Call the Yahoo geocoder with the given address information.
'
'***************************************************************************
function geocode( street, city, state, zip )
dim url
Dim doc
output = m_output
Set doc=CreateObject("Microsoft.XMLDOM")
doc.async=false
call doc.setProperty("ServerHTTPRequest",true)
url="http://local.yahooapis.com/MapsService/V1/geocode" & _
"?appid=" & appid & _
"&street=" & street & _
"&city=" & city & _
"&state=" & state & _
"&zip=" & zip & _
"&output=" & output
m_url = url
doc.load( url )
m_lat = 0.0
m_lon = 0.0
m_street = ""
m_city = ""
m_state = ""
m_zip = ""
m_country = ""
m_xml = "not loaded"
m_precision = "failed"
if doc.parseError.errorcode=0 then
'' Now check if we have a YAHOO error
if isError( doc ) = true then
m_reason = GetXMLValue( doc, "/Error/Message" )
else
' proceed
m_precision = GetPrecision( doc )
m_lat = GetXMLValue( doc, "Latitude" )
m_lon = GetXMLValue( doc, "Longitude" )
m_street = GetXMLValue( doc, "Address" )
m_city = GetXMLValue( doc, "City" )
m_state = GetXMLValue( doc, "State" )
m_zip = GetXMLValue( doc, "Zip" )
m_country = GetXMLValue( doc, "Country" )
m_reason = ""
end if
m_xml = doc.xml
else
m_reason = doc.parseError.reason & " line: " & doc.parseError.line
m_xml = doc.text
'' Error code here
end if
set doc = nothing
end function
'***************************************************************************
' Copyright 2010 Larry Boeldt
' Function: isError Version 1.0 11:11 AM Sunday, June 27, 2010
' Author: Larry Boeldt
' Terms:
' GPL, commercial license available
'
' Parameter(s):
' Doc XML Document from Yahoo
'
' Return Value:
' True if document is a Yahoo! Error document
' False if document is a valid data packet from yahoo
'
' Description:
' Determine if returned documen is a Yahoo error document
'
'***************************************************************************
function isError( doc )
dim bResult
if GetXMLValue( doc, "/Error/Message" ) = "" then
bResult = false
else
bResult = true
end if
end function
end class '' YGeocoder
%>
|
lboeldt
Posts: 53
|
Posted: 06/27/2010, 10:10 AM |
|
Here is a code sample that makes a call to the main function Geocode( address, city, state, zip)
<%
'' Test YGeoCoder class
'' Test Address:
'' 1600 Pennsylvania Avenue NW
'' Washington, DC 20500
dim geo
dim address
dim city
dim state
dim zip
address = "1600 Pennsylvania Avenue NW"
zip = "20500"
city = ""
state = ""
'' Create an instance of the class
set geo = new YGeoCoder
call geo.geocode( address, city, state, zip )
'' Return Results as JSON object.
response.write "{ result: '" & geo.precision & "', "
response.write " lon: " & geo.lon & ", "
response.write " lat: " & geo.lat & ", "
response.write " reason: '" & geo.reason & "', "
response.write " city: '" & geo.city & "', "
response.write " state: '" & geo.state & "', "
response.write " zip: '" & geo.zip & "', "
response.write " country: '" & geo.country & "', "
response.write " address: '" & geo.address & "', "
response.write " url: '" & geo.url & "' "
response.write "}"
set geo=nothing
%>
|