Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

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 (19,892 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="http://www.w3.org/ns/widgets" 
	<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="blackberry.app" 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 gpsDemo.zip 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.


by Developer
on ‎06-23-2011 02:05 PM

Are the first 2 steps still required with Webworks 2.1?

by Retired
on ‎07-21-2011 07:17 PM

This article has been updated to reflect v2.1.   Developers no longer need to modify the global bbwp.properties file.  Now permissions support comes directly from the application's config.xml file.

Users Online
Currently online: 23 members 3,535 guests
Please welcome our newest community members: