How to Incorporate Location into Your BlackBerry Applications
If you have ever been in an unfamiliar place or stuck in traffic and looking for an alternate route, then you already know the magic that is GPS. One of the hottest areas in smartphone development today is location-based services, and BlackBerry is on the cutting edge when it comes to providing those services. In this article we will discuss BlackBerry’s support of JSR 179, and learn to incorporate GPS functionality into our applications.
Before we delve in any further into this article, I am going to assume that you are already familiar with programming basic BlackBerry applications, and that you have the required development environments and simulators installed on your computer. If not, I suggest taking a peek at BlackBerry's Developer Zone to get up to speed.
GPS Information and the BlackBerry
Not all BlackBerry devices support GPS (Global Positioning System) technology, but on the ones that do, applications exist that allow the user to display their current position on a map in real time. In addition, applications can supply directions, both textual and image-driven, and suggest alternate routes. They can even give the user satellite and street level imagery. To achieve these wonders, BlackBerry applications rely on the Location API for Java Platform (JSR 179). We will be working with this JSR throughout the remainder of this article.
For starters, we will look at methods and modes used to obtain local GPS information. There are three Location modes available to use. The first is cell site, which lets us retrieve information from cell site towers and the strength of the user's signal. Of all the location modes, this method is the fastest, but be forewarned - that speed comes with a disadvantage: the accuracy is sub-par and you cannot obtain speed or routing information. Note that cell site support depends on the carrier.
To get location information using the cell site mode, create a new Criteria object, like so:
Criteria criteria = new Criteria():
Next you will need to Invoke the following:
criteria.setHorizontalAccuracy(NO_REQUIREMENT); //this tells the program that there is no requirement for longitude accuracy
criteria.setVerticalAccuracy(NO_REQUIREMENT); //the same as above, but with regards to latitude
criteria.setCostAllowed(true); //specifies that the cell site mode can result in a fee
setPreferredPowerConsumption(POWER_USAGE_LOW); //set the power consumption to low
After this you will need to invoke LocationProvider.getInstance(), which in turn stores the information in a LocationProvider object. To do so, type in the following: