07-28-2010 11:37 AM
My app uses code from the GPS demo and am trying to acquire location using cellsites.
I am seeing two issues:
1. The code works on a 9550 simulator but does not return from a getLocation(-1) call on a Bold 9700 device
2. When in setupCriteria I use, the code hangs on that line.
Any pointers will be appreciated.
thanks
//myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);
The code looks like this:
private void setupCriteria(){
_criteria = new Criteria();
_criteria.setHorizontalAccuracy(Criteria.NO_REQUIR EMENT);
_criteria.setVerticalAccuracy(Criteria.NO_REQUIREM ENT);
_criteria.setCostAllowed(true);
_criteria.setPreferredPowerConsumption(Criteria.PO WER_USAGE_LOW);
//myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);
}
private void createLocationProvider(){
try {
_provider = LocationProvider.getInstance(myCriteria);
} catch (LocationException e) {
status("Error in location acquisition");
}
}
private void getSingleFix(){
new Thread(){
public void run(){
resetProvider();
setupCriteria();
createLocationProvider();
try {
_location =_provider.getLocation(-1);
} catch (LocationException e) {
status("Error in location acquisition");
} catch (InterruptedException e) {
status("Error in location acquisition");
}
if(_location!=null && _location.isValid()){
QualifiedCoordinates coordinates = _location.getQualifiedCoordinates();
double lat = coordinates.getLatitude();
double longit = coordinates.getLongitude();
latlong(lat, longit); status(" ");
log("In loc valid");
} else{
status("Error in location acquisition");
}
}
}.start();
}
private void resetProvider(){
if(_provider!=null){
_provider.setLocationListener(null, 0, 0, 0);
_provider.reset();
_provider=null;
}
}
public void locationUpdated(LocationProvider provider, Location location) {
if(location!=null && location.isValid()){
QualifiedCoordinates coordinates = location.getQualifiedCoordinates();
double lat = coordinates.getLatitude();
double longit = coordinates.getLongitude();
latlong(lat, longit);
status(" ");
} else{
status("Error in location acquisition");
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
/**
* not implemented. For more information on how to implement this method please
* refer to the BlackBerry Developer Knowledge Base Articles.
*/
}
Solved! Go to Solution.
07-28-2010 11:50 AM
Try setting Power Consumption to High and see if that works.
My GPS app appears to either hang or throw a null pointer exception when I try and use Power Consumptin set to low on my BB 9700.
criteria.setPreferredPowerConsumption(
Criteria.POWER_USAGE_HIGH);
07-28-2010 11:54 AM
Setting POWER_USAGE_HIGH made it work.
Thanks
07-28-2010 04:52 PM
Testing the fix inside a building where there's no GPS, sometimes it works and other times it does not work.
Any ideas on how to make more consistent in acquiring a location using cell sites?
07-29-2010 05:43 AM - edited 07-29-2010 11:04 AM
I use;
if (location != null && location.isValid()) {
To add the Latitude & Longitude to the string I send back to the server. If this data is null then when it is processed by my EJB on the server it uses the Cell ID & LAC code to get the Latitude & Longitude.
Ideally you (we) should be using;
public void providerStateChanged(final LocationProvider provider, final int newState) {
There is a bug and this method is never called, well at least not on the Bold 9700. It has been raised on the BB bug tracker. See my post;
If this is effecting you perhaps you can vote for it to be fixed? The more the merrier!