I have to say that this, and the prospect of using BBEC & RE in the Cloud, is a great direction for Blackbaud to be moving in and I think it really outlines just how agile the Infinity platform really is.
Anyway, have a look!
AJParise wrote: In January 2008, I started working extensivley with the REAPI.After a year of headaches and mindnumbing research I've developed some very handy classes for .NET developers using the 3.5 framework looking to integrate with the REAPI.
'''''' this method will take a REID and get the address''' then it will use google maps to lookup that address address''' note: the value of the returned array with the lat/lng is nothing if''' either the address coudln't be geocoded or it wasnt' specific enough to get back a single result''''''''''''
_Public Function getConstitLatLng(ByVal sREID As String) As ArrayListDim oConstit As New CRecord 'this is the constit objectDim aLatLng As New ArrayList(2) 'we'll be returning this.Dim RE7 As REAPI = initAPI() 'this is located in the source. be sure to change up your serial, username, pass and db number.Dim oAddress As CConstitAddress 'address objectTryWith oConstit.Init(RE7.SessionContext) 'init.Load(sREID) 'load the passed in REIDFor Each oAddress In .Addresses 'loop over all the addressesIf oAddress.Fields(ECONSTIT_ADDRESSFields.CONSTIT_ADDRESS_fld_PREFERRED) = -1 Then 'grab the prefered one, yes I know it's -1 trust me on this -1 = true for some strange reason in the BBREAPI...I don't ask questions if it works.'pass the retrieved criteria to the seekCoords methodaLatLng = getCoords(oAddress.Fields(ECONSTIT_ADDRESSFields.CONSTIT_ADDRESS_fld_ADDRESS_BLOCK) & " " & oAddress.Fields(ECONSTIT_ADDRESSFields.CONSTIT_ADDRESS_fld_CITY) & ", " & oAddress.Fields(ECONSTIT_ADDRESSFields.CONSTIT_ADDRESS_fld_STATE) & " " & oAddress.Fields(ECONSTIT_ADDRESSFields.CONSTIT_ADDRESS_fld_POST_CODE))Exit ForEnd IfNextEnd WithFinally 'close down your stuff...alwaysoConstit.CloseDown()System.Runtime.InteropServices.Marshal.ReleaseComObject(oConstit)System.Runtime.InteropServices.Marshal.ReleaseComObject(RE7)End TryReturn aLatLng 'return the valueEnd Function
Private Function getCoords(ByVal sAddress As String) As ArrayListDim stream As IO.Stream = NothingDim doc As XmlDocumentDim req As HttpWebRequestDim aLatLng As New ArrayListIf sAddress <> "" Then 'we check to make sure that we have an addressreq = DirectCast(WebRequest.Create("http://maps.google.com/maps?output=kml&q=" + sAddress), HttpWebRequest) 'pass the address to googole and assign the results to req'now we parse up the results'generally speaking kml = xml so we can use the std handlers in .net for this'why google doesn't just call it xml is beyond meDim response As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)stream = response.GetResponseStream()Dim sr As New StreamReader(stream)Dim text As String = ""text = sr.ReadToEnd()sr.Close()doc = New XmlDocument()doc.LoadXml(text)longitudes = doc.GetElementsByTagName("longitude")latitudes = doc.GetElementsByTagName("latitude")'for simplicty we only want to worry about results that have 1 possible result'none, means the address wasn't geocodable'multiple means the address wasn't specific enoughIf longitudes.Count = 1 ThenaLatLng.Add(latitudes(0).InnerText)aLatLng.Add(longitudes(0).InnerText)End IfEnd IfReturn aLatLngEnd Function