Smartphone Development Page 2 - How to Incorporate Location into Your BlackBerry Applications |
The second location mode we can use to retrieve data is the assisted mode. This mode obtains information via satellites with a Position Determination Entity, or PDE. The up side to this method is that it is more accurate than the cell site mode, and faster than the third method (autonomous). The down side is that it is not as accurate as the autonomous method, except in a few rare situations. To get the location using the assisted mode, create a new Criteria object, in the following manner: Criteria criteria = new Criteria(): Next you will want to Invoke the following: criteria.setHorizontalAccuracy(100); //indicates that there is a requirement for horizontal accuracy criteria.setVerticalAccuracy(NO_REQUIREMENT); //indicates that there is no accuracy required for latitude criteria.setCostAllowed(true); //indicates that the cell site mode can result in a fee criteria.setPreferredPowerConsumption(POWER_USAGE_MEDIUM) //tells the program that there is a medium power usage requirement The last thing to do is to Invoke LocationProvider.getInstance(), which stores the information in a LocationProvider object: LocationProvider provider = LocationProvider.getInstance(criteria); Getting Information with GPS The last location mode is known as autonomous, as referenced above. This information is retrieved from a GPS receiver on the BlackBerry device and does not rely on a wireless network. It provides the best accuracy for location, but unfortunately is slower than the other methods in terms of time-to-first-fix. If we wish to get accurate information, we do as before -- create an instance of a Criteria object, using the same method as before: Criteria criteria = new Criteria(): Then we will Invoke the following, this time changing our requirement: criteria.setHorizontalAccuracy(50); //indicates that there is a requirement for longitudinal accuracy (this value is optional) criteria.setVerticalAccuracy(50); //indicates that there is a requirement for latitudinal accuracy (this value is optional) Note that both of these values require a value in meters. If we wish to get an approximate value, we do so like this: criteria.setHorizontalAccuracy(NO_REQUIREMENT); // that there is no accuracy required for longitude criteria.setVerticalAccuracy(NO_REQUIREMENT); // that there is no accuracy required for latitude Next we will deny fees: criteria.setCostAllowed(false) And finally, we need to create a LocationProvider object based on these criteria: LocationProvider provider = LocationProvider.getInstance(criteria); There are a few other methods for retrieving and storing location information; we will touch upon those in a later article. For now though, let's move on and learn to actually display the data.
blog comments powered by Disqus |
|
|
|
|
|
|
|