Skip to Content

Using location services to store Portal user details

Many mobile devices have the ability to display details about where the user is located. So, why not try to capture this and present it with the ubiquitous Google map mechanism? Here’s a possible way to do this…

The first thing I wanted to do was store the latitude and longitude of the portal user. Ok, first we have to capture it, but there’s no point doing that unless we can persist it. I decided to use a feature of the AS Java UME (User Management Engine) which allows you to store extra metadata about users. This is achieved by changing a few UME parameters and then restarting the AS Java. I generally use the configeditor of the config tool. The parameters in question are ume.admin.addattrs and ume.admin.public.addattrs. I decided to use two extra fields, lat and long.

The contents of these fields can be seen, and modified, using the /useradmin tool. The extra fields appear on the Customized Information tab.

 However, the idea is to use the location services. I found a sample bit of code on the internet and converted it to a portal component. In my NWDS project Mobile my component for this is GetLocation. When this component is started, it checks whether location services are enabled and if so, asks the user to confirm that it is OK to store their location details. The mobile device will first ask the user if it is OK to capture the location.

The component to store the details is called StoreCoords. It is passed the collected latitude and longitude and uses a standard set of UME APIs to store the lat and long fields defined earlier.

Starting the component:

When you select OK, a new screen appears:

When you use the “Store my location” link, the UM data is updated with your latitude and longitude and a result is displayed:

Now we want to display the details. Another portal component called ShowUserLocations is used for this. It presents either a Google map showing the user locations, or optionally can be used to create a KML response, by adding ?kml=yes when the component is invoked. The KML response can be used to launch Google Earth and allows for the traditional zooming over the globe.

Here’s what it looks like after I store my location when I am located in Sydney:

Rather that post code fragments, I have uploaded the PAR file, with all the source, to 

You must be Logged on to comment or reply to a post.