Monday, August 21, 2006

GOOGLE API - Geolocalisation search from Lotus Notes client

It's possible to search geolocalisation of an postal address from Lotus Notes client too.


ALAX : Asynchronous LotusScript And XML

To search the geolocalisation of a postal address from Lotus Notes Client, I use XMLHTTP object like in AJAX solutions. This object can be used in lotuscript thru agent, event or action.

Search Form

The elements of my form are :

  • "street" : text field
  • "town" : text field
  • "country" : text filed
  • button "search"
  • "latitude" : text field
  • "longitude" : text field
The user will specify street, town and town, then will click on search button. The values of Lattitude and longititude fields will be automatically added.

Search button

I use the same web service than previous entry. The function must :
  • format search query from fields values
  • send request to web service
  • parse the result
  • added values to longitude and latitude fields
The LotusScript code :
Sub Click(Source As Button)
Dim wk As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim street, town, country As Variant

Set uidoc = wk.CurrentDocument
Set doc = uidoc.Document

' longitude/latitude search request
' -----------------------------------------------------------
' the text must be encoded in URL format to replace special characters
' and spaces. localsearchmaps web service doesn't accept null value
' for street. If the user doesn't specify this information, we'll send
' "%20"

street = Evaluate({@URLEncode("UTF-8";"} + doc.street(0) + {")})
If street(0)="" Then street(0) = "%20"
town = Evaluate({@URLEncode("UTF-8";"} + doc.town(0) + {")})
country = Evaluate({@URLEncode("UTF-8";"} + doc.country(0) + {")})
request = "http://www.localsearchmaps.com/geo/?street=" + street(0) + _
"&city=" + town(0) + "&country=" + country(0) + "&cb=notes"

' Call and reception of the request
' -------------------------------------------------------------
' The XMLHTTP object only work if user have Internet Explorer

Set page = CreateObject("Microsoft.XMLHTTP")
Call page.open("GET", request, False)
Call page.send()

strReturn =page.responseText

If (Instr(strReturn,"notes")>0) Then
' Extraction of longitude and latitude
' ----------------------------------------------------
' The result of the request looks like :
' notes(latitude, longitude,'TOWN', 'CODE', 'COUNTRY');

search = Mid(strReturn, 7, Instr(strReturn, ",'") -7)
lattitude = Left(search, Instr(search, ",") -1)
longitude = Mid(search, Instr(search, ",") +2)

Call uidoc.FieldSetText("latitude", lattitude)
Call uidoc.FieldSetText("longitude", longitude)
Else
Messagebox "The postal address wasn't found", 48, "Geolocalisation"
End If

Set page = Nothing
End Sub

2 comments:

Ulrich Krause said...

Hi,

exactly what I was looking for.

There is a small typo in the source:

http://www.localsearchmaps.com/geo/?street=" + country(0) +

should be

http://www.localsearchmaps.com/geo/?street=" + street(0) +

Philippe GAUVIN said...

OOps ! Sorry. I've changed the code.

Just another information. I've discovered Google has recently added a similar web service but I haven't tested it for the moment.