I'm a huge Blackberry fan.  I have had a Blackberry for close to 6 years now and have never looked back. They do what they are designed to do (email and phone), no questions asked.  I've used windows mobile phones and have a few friends that have them and it seams like they are always having issues.  The iPhone is definitely a strong competitor but without a real keyboard and push email its not an option for me.  There is one huge are area that Blackberrys and RIM (Research In Motion) is lacking in and that's developer support. While there are many things to complain about the issue that pains me the most as a web developer is the Blackberry Browser.

The iPhone browser rocks.  The Blackberry Browser doesn't.  Its like developing for IE 4.0.  There is limited xhtml  and css support and if you follow the documentation its possible to create a functional website that looks decent  on the device.  There is very little javascript support, but it does have support to get GPS coordinates from a device with builtin GPS, like the Blackberry 8800, 8820, and 8310, which could be used to create some very cool location based websites.  Unfortunately the documentation is completely wrong.   The information in the content developer guide is just plain wrong and sample code on the blackberry developer website isn't even valid javascript.

Here is what I have found to be a more accurate description of the blackberry.location javascript API in the blackberry browser based on my testing using a Blackberry 8800 running v4.1.1.90:

gpsblackberry.location.latitude & blackberry.location.longitude:
The current latitude and longitude of the device.  The first time you access either of these properties the user is prompted if they would like to let the website access location information.  There is currently no setting on the device or on the enterprise server to disable this prompt or whitelist specific sites. If the user selects "No" then "0" will be returned for the latitude & longitude.

This method sets the GPS aid mode to be used. 0 - Cell Site, 1 - Assisted, 2 - Autonomous.  The documentation is mostly correct on this method. "Autonomous" is the most accurate and most supported but also the slowest. The other two methods require carrier support and my carrier doesn't support it so I couldn't test them.

This method request and update of the location from the device.  This method is non-blocking so if you try to read the laitude/longitude right after calling this method you may or may not get the newest information.  This method returns true on success.  If you have set an invalid AidMode (0 or 1 and the carrier doesn't support that feature) this method will return false and the callback method will never be called.

This method is the worst a far as incorrect documentation goes.  This method sets a callback function that is called after you call refreshLocation() and the device actually has the new location data.  However in my testing it appears that this does not get called once per refreshLocation() call.  After you call refreshLocation() the callback function is invoked continuously when the location changes (about every 10-15 seconds in my testing). Another very important note is that you have to pass this method a string that gets evail-ed (like you can do with setTimeout).


Here is a sample that puts all of the pieces together.  It simply shows a javascript alert with the latitude and longitude when the location is updated:

   1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
   2: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   3:   <head>
   4:     <title>GPS Testing</title>
   5:     <script "text/javascript">
   7:       // called when location object changes
   8:       function locationCB()
   9:       {
  10:           alert("Latitude "  +
  11:               blackberry.location.latitude);
  12:           alert("Longitude " +
  13:               blackberry.location.longitude);
  14:           return true;
  15:       }
  17:       // test to see if the blackberry location API is supported
  18:       if( window.blackberry && blackberry.location.GPSSupported) {
  19:             document.write("GPS Supported");
  22:             // Set our call back function
  24:             //WRONG: this would call our call back function immediatly, not after the refresh
  25:             //blackberry.location.onLocationUpdate(locationCB());
  27:             //WRONG: the blackberry browser won't support passing a method.
  28:             //It will error on refresh and all javascript processing on the page will stop
  29:             //blackberry.location.onLocationUpdate(locationCB());
  32:             // RIGHT: pass a string that calls our method
  33:             blackberry.location.onLocationUpdate("locationCB()");
  35:             // set to Autonomous mode
  36:             blackberry.location.setAidMode(2);
  38:             //refresh the location
  39:             blackberry.location.refreshLocation();
  40:       }    
  41:       else
  42:       {
  43:         document.write("This Device doesn't support the Blackberry Location API");
  44:       }
  45:     </script>
  47:   </head>
  48:   <body>
  49:   </body>
  50: </html>


Hopefully someday we will get a more feature rich, fully documented, Blackberry browser with DOM and AJAX support  (Firefox mobile anyone?).  Until then hopefully I have saved someone days of debugging incorrectly documented features.

Posted at 5/8/2008 2:40 AM
Comments [16] - Permalink
Saturday, 28 June 2008 16:02:33 (Eastern Daylight Time, UTC-04:00)
Nice article, thank you. An improved Blackberry browser indeed would be sweet.

Thanks again,
Tuesday, 02 September 2008 04:42:00 (Eastern Daylight Time, UTC-04:00)
Nice article. The code worked as advertised in the 8130 and 8330 simulators. When I tried the code out on my Verizonwireless 8330, it didn't work. Of course, I know now that Verizon has disabled the GPS unless you pay for VZNavigator at $9.99 per month. All of you with Verizon consider this a warning and don't waste your time trying to get it to work.

Thanks for the great code!

Robert Markowitz
Monday, 26 January 2009 23:43:37 (Eastern Standard Time, UTC-05:00)
Have you taken a look at Opera Mini on the Blackberry? I used to use it, when I was a Blackberry guy, and everyone I have pointed to it seems to stick with it on their Blackberry devices for daily browsing purposes.
Thursday, 05 February 2009 16:32:44 (Eastern Standard Time, UTC-05:00)
does anyone know of an app out there that can obtaint the gps location on a bb and send that to a server via url?

Sunday, 29 March 2009 15:20:29 (Eastern Standard Time, UTC-05:00)
Thanks, just what I needed.
Thursday, 04 June 2009 12:47:47 (Eastern Daylight Time, UTC-04:00)
Matt wrote... does anyone know of an app out there that can obtaint the gps location on a bb and send that to a server via url?

Yes. It will be in the public domain by the end of June.

Monday, 08 June 2009 10:09:46 (Eastern Daylight Time, UTC-04:00)
I have a Blackberry 8100 Pearl and want to get a external bluetooth GPS receiver.

(8100 Pearl doesnt have internal GPS)

Will this code work even though I am using the external bluetooth GPS receiver?

Jaco Ras
Monday, 08 June 2009 12:54:28 (Eastern Daylight Time, UTC-04:00)

Good question. I'll check for you. Currently we test using the internal GPS which already has a documented API. However it wouldn't be that hard to write an app that reads the Bluetooth COM port that is accessing the GPS, grab that data and then send it to our app (which does have a set of open API's so that developers can extend it to other sensors i.e. blood pressure cuff).


Monday, 08 June 2009 13:01:52 (Eastern Daylight Time, UTC-04:00)

Just checked and we have tested the BB Curve using an external GPS puck and it works just fine. You can send the location to any web site you desire using the standard Internet BB browser.


Tuesday, 16 June 2009 23:38:11 (Eastern Daylight Time, UTC-04:00)
Is it possible for javascript running in the Blackberry browser to monitor location and send http requests while the browser is in the background?
Wednesday, 08 July 2009 06:02:50 (Eastern Daylight Time, UTC-04:00)
Hi Peter,

Quick question:

Will the GPS be automatically be enabled on request through the browser?

Or do first have to activate GPS before going on browser?

(Pity I dont have a Blackberry to test on)
Jaco Ras
Tuesday, 08 September 2009 14:33:48 (Eastern Daylight Time, UTC-04:00)
Hi All,

Is there away to turn of the pop-up containing "A JavaScript has requested the physical location of your device. Do you wish to provide this to the script" after you have accepted access JavaScript code on entering the page.

Basically what happens I send the lat & lng with window.location.href when the locationCB() function is invoked this reloads the page and the pop-up appears again is there some way to create session so that the browser don't ask the question again on each reload.

Thanks for the help..


Saturday, 13 March 2010 16:39:19 (Eastern Standard Time, UTC-05:00)
I tried the above example code on BB simulator 8820. I have made a simple web application using Eclipse IDE which serves this code as index.html. I run this application on Tomcat. When I hit the application through BB simulator browser, it says that latitude and longitude, both are 0 and after sometime, my Eclipse IDE crashes.

Could you please explain the reason behind that.

Kapil Shardha
Friday, 18 June 2010 00:47:54 (Eastern Daylight Time, UTC-04:00)
i tried your code in blackberry 9630 simulator, but getting zero for both lattitude and longitude.
Any suggestions

Thursday, 31 March 2011 15:01:17 (Eastern Standard Time, UTC-05:00)
For all the Blackberry fans in the world, let's hope that this browser weakness is addressed in the near future.
Wednesday, 12 October 2011 15:47:02 (Eastern Daylight Time, UTC-04:00)
We are developing a native blackberry application which needs to capture GPS and/or cell-tower information on a periodic basis (every 1 hour). The code seems to work properly when tested by our developers in India but it doesnt work on our blackberry in the US (Verizon; 9650). The developers are saying that we need to go through an approval process with Verizon in order to be able to collect location information.

Can someone please help us understand whether (a) we do need Verizon's approval, (b) any leads on how we do this and how long it takes, (c) do other major carriers also require the same/similar approvals (AT&T, T-Mobile, Sprint), (d) how do other apps such as Foursquare, Facebook etc collect location information (do they go through the same process)?

Thanks for the help!

Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, i) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview