How To - Enable GPS capability in BlackBerry WebWorks for Tablet OS development

by Retired on ‎04-28-2011 02:57 PM - edited on ‎07-19-2011 01:32 PM by Retired (20,005 Views)

What is it?


Applications created using the BlackBerry® WebWorks™ SDK for Tablet OS can leverage the GPS capability of the BlackBerry® PlayBook™ tablet in order to retrieve current GPS coordinates.


The BlackBerry® Tablet OS currently supports the following two types of GPS modes:


  • Using an internal GPS chip, device computes a fix by communicating with satellites only
  • Requires a clear view of the sky
  • No data connectivity required
  • Relatively higher Average Time To First Fix (TTFF)
WLAN Geolocation
  • Computes location based on WLAN access points
  • Requires the device to be provisioned with this service
  • Requires WLAN connection point be registered with RIM's Geolocation service
  • Less accurate than standalone GPS but must faster to acquire a GPS position


Note: The Tablet OS will decide to use standalone GPS  coordinates if they are available, and then WLAN as a second choice.


How to enable?



1) Edit the config.xml file for your BlackBerry WebWorks application, add the following read_geolocation permission element:



<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="" 
	<name>Geolocation Demo</name>

	<icon src="img/icon.png"/>
	<content src="index.html"/>
 <rim:permissions> <rim:permit>read_geolocation</rim:permit> </rim:permissions>
	<feature id="" required="true" version=""/>



2) Compile your application using the BlackBerry WebWorks SDK for Tablet OS (See Windows® or Mac instructions).



How to retrieve GPS coordinates?


As demontrated in the knowledge base article Using HTML5 Geolocation in your Web or BlackBerry WebWorks applications, retrieving GPS coordinates within BlackBerry WebWorks applications use the HTML5 Geolocation APIs:



function geolocationSuccess(position) 
   var lat = position.coords.latitude;
   var lon = position.coords.longitude;
   alert("location: " + lat + "," + lon);
function geolocationError(posError) {
   alert("Error " + posError.code + " : " + posError.message);
function getPosition(params) {
   navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, null);



Application Permissions Prompts


Once the read_geolocation permission has been defined in config.xml, the BlackBerry WebWorks SDK for Tablet OS will build GPS support into the BlackBerry WebWorks application that it compiles.  This means that when a user opens the application, they will immediately be prompted to allow or deny the application from accessing GPS location information:  




This permission prompt will only occur the first time the application is opened, however will always occur regardless of whether the given application even uses GPS information.  For this reason, it is recommended to only include the read_geolocation <permission> element in your config.xml file when you are producing GPS-powered applications.  


Tip: As a rule of thumb, if your application does not use GPS,

do not make the above change to config.xml.




More Info:


The source code for a sample application has been included as an attachement at the end of this article.  Download and build it using the BlackBerry WebWorks SDK for Tablet OS.  Load this application on a live BlackBerry PlayBook tablet to see how GPS location information can be used.