Server-Side Apps with access to device functionality aka. accessing the iOS Geolocation API with Java.

May 3, 2012 | 2 min Read

Whenever we talk about server-side apps and RAP mobile, one topic always comes up: how to access native functionality like Geolocation or the Camera. With this post I want to show you how we access this functionality on the server-side. At writing, we’ve implemented Geolocation Support, and more additions are planned for the near future.

I have to point out one thing first.  When you take look at RAP mobile from a very abstract view, it is nothing more than an object synchronization mechanism. That is, if a button (or any other widget) is created on the server it also needs to be created on the client. This is exactly the same for native functionality. When the server needs the location of the client it has to tell the client that it needs the location. Then, the client has to tell the server the location and this cycle starts over again. The challenge in this approach is to hook the location to the right session. Fortunately, RAP’s server side has solved these issues a long time ago, and it’s pretty easy to hook this information together.

One issue that remains is that SWT has no API for native access because it was made for the desktop. So, a new API is required that needs be an abstraction for all devices. But wait a minute - this sounds like a well known problem that has been solved already. I’m referring to Phonegap/Cordova. This technology created a JavaScript abstraction for accessing native functionality within HTML5 Apps. And, IMHO, these guys did a really great job and there is no need to reinvent the wheel. We decided to take the Phonegap API as a template and created a very similar Java API. Our first result is the Geolocation API which is located in the RAP mobile server code. As mentioned in previous posts, everything on the server side is open source, including this API. The RAP mobile server code is located in the*.jar and is included in the demos target. You can also take a look the Geolocation API here at github.

We have created a demo for the Location API, which you can see in the videos linked below. The source code for this demo is also located on github. To conclude, I can proudly say that with RAP mobile it’s now possible to access the Geolocation API of iOS and Android from Java by writing the code only once!

[vimeo w=500&h=400] [vimeo w=500&h=400]