Capturing geodata in XPages

In XPages it is not default possible to capture geodata information with any control so you are depending on services (not a problem if they provide the correct data).

Here is an example how to capture a visitor’s geodata via and store the information in a Notes document in the following order:

  • Run client side JavaScript  (jQuery get method) and load data from an external server.
  • Post the data via client side JavaScript (jQuery post method) to an XPage.
  • Process the data and store it in a Notes document.

Place the following code on an XPage:

<script language=”javascript” type=”text/javascript” src=”jquery.js”></script>
<xp:scriptBlock id=”scriptBlock1″>
$.get(‘;, function (response) {
$(‘#ip’).html(‘IP: ‘ + response.ip);
$(‘#address’).html(‘Location: ‘ + + ‘, ‘ + response.region);
$(‘#details’).html(JSON.stringify(response, null, 4));
type: ‘POST’,
url: ‘postCreateCountMe.xsp?city=’ + + ‘&region=’ + response.region + ‘&country=’ + + ‘&loc=’ + response.loc
}, ‘jsonp’)
Client side IP geolocation using
<a href=””></a&gt;
<hr />
<div id=”ip”></div>
<div id=”address”></div>
<hr />
Full response:
<pre id=”details”></pre>


We assume you have jQuery stored in your application. Add it as a resource to your XPage. When the document is fully loaded we make a call to the external service, the response received we process. For demo purpose we also display it on the screen:


At the end we make a post to a second XPage which will process the received data into a Notes document. We attach the data as parameters to the URL. The code for this XPage looks as followed:

<xp:script src=”/xpCGIVariables.jss” clientSide=”false”></xp:script>
<xp:this.afterRenderResponse><![CDATA[#{javascript:var dt:NotesDateTime = session.createDateTime(“Today”);
function createDoc(){
var doc = database.createDocument(); // Create the document
doc.appendItemValue(“Form”,”count”); // Assign the form
doc.appendItemValue(“date”,dt); // Append something to a field

var udt:NotesDateTime = session.createDateTime(“Today”);
var unixDate = parseInt(udt.toJavaDate().getTime()/1000);
//the time format usable in plotter:
var unixDateOnly = parseInt(udt.toJavaDate().getTime()/100000000)*100000*1000;

doc.appendItemValue(“dateunix”,unixDate); // Append something to a field
doc.appendItemValue(“dateonlyunix”,unixDateOnly); // Append something to a field

var cgi = new CGIVariables()
var browser = cgi.HTTP_USER_AGENT
doc.appendItemValue(“browser”,browser); // Append something to a field
var user = @UserName();
doc.appendItemValue(“user”,user); // Append something to a field

var page = facesContext.getExternalContext().getRequest().getRequestURI();
var page = view.getPageName()
doc.appendItemValue(“pagename”,@RightBack(page,”/”)); // Append something to a field

var _param1 = param.get( ‘city’ );
var _param2 = param.get( ‘region’ );
var _param3 = param.get( ‘country’ );
var _param4 = param.get( ‘loc’ );
doc.appendItemValue(“city”,_param1); // Append something to a field



We use the infamous CGI variables SSJS library written by Thomas Gumz, IBM so we can add some additional CGI variables on the Notes document. So add this library to the XPage resources section.

After the page is rendered we execute code. Besides some CGI variables we process the data in the included parameters.

In the end your Notes document could look as followed:





The idea is simple, also the implementation. Now I just need to find a nice GeoData chart to visualize the collected data. Do you got any suggestion(s)?

Ps. Does anyone read the information below???

Job Wanted

Looking for a creative brain? Choose me!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s