Error handling
You can retrieve the last error that was received when a GPS fix is unsuccessful by invoking GPSInfo.getLastGPSError(), available in the JSR 179 Location API, or BlackBerryLocation.getError(), available in the BlackBerry extensions to JSR 179.
Handle errors (JSR 179)
Handle errors (BlackBerry extensions to JSR 179)
You can check the status of a GPS fix request by invoking the getStatus() method that is provided in the BlackBerry extensions to JSR 179. If the return is BlackBerryLocation.GPS_ERROR, you can retrieve the error value by invoking BlackBerryLocation.getError().
Code sample: Handling errors (BlackBerry extensions to JSR 179)
import net.rim.device.api.gps.*;
import javax.microedition.location.*;
public class handleGPS
{
public handleGPS()
{
try
{
BlackBerryCriteria myCriteria =
new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST);
try
{
BlackBerryLocationProvider myProvider =
(BlackBerryLocationProvider)
LocationProvider.getInstance(myCriteria);
myProvider.setLocationListener
(new myLocationListener(), -1, -1, -1);
}
catch ( LocationException lex )
{
return;
}
}
catch ( UnsupportedOperationException ex )
{
return;
}
}
private static class myLocationListener implements LocationListener
{
public void locationUpdated
(LocationProvider provider, Location location)
{
if (location instanceof BlackBerryLocation)
{
BlackBerryLocation bLoc = (BlackBerryLocation)location;
switch(bLoc.getStatus())
{
case BlackBerryLocation.GPS_ERROR:
int gpsStatus = bLoc.getError();
break;
case BlackBerryLocation.FAILOVER_MODE_ON:
case BlackBerryLocation.SUBSEQUENT_MODE_ON:
case BlackBerryLocation.GPS_FIX_PARTIAL:
case BlackBerryLocation.GPS_FIX_COMPLETE:
break;
}
}
}
public void providerStateChanged
(LocationProvider provider, int newState)
{
}
}
}
Next topic: Retrieve a GPS location by using a web page