public void locationUpdated(LocationProvider provider, Location location) {
if(provider != this.locationProviderReference){ // if this is an update from an old location provider that is in the process of being stopped, ignore the update.
return;
}
BlackBerryLocation bbLocation = (BlackBerryLocation) location;
if(bbLocation!=null && bbLocation.isValid() && (bbLocation.getQualifiedCoordinates().getLatitude()!=0 && bbLocation.getQualifiedCoordinates().getLongitude()!=0)){
log("Tracking: Acquired valid location - " + location.getQualifiedCoordinates().getLatitude() + ", " + location.getQualifiedCoordinates().getLongitude());
this.location = (BlackBerryLocation) location;
/**
* retryAttempt should not be reset in MODE_OPTIMAL when currentOptimalModeIsGeolocation
* because last GPS fix might have failed and this is only a fall back to Geolocation that has passed.
* We still need to preserve the retryAttempt until a GPS fix works in MODE_OPTIMAL. Otherwise
* we will simply waste battery by trying GPS fixes too frequently when it is not available.
*/
if( mode!=MODE_OPTIMAL || (mode==MODE_OPTIMAL && !currentOptimalModeIsGeolocation) ){
retryAttempt = 0;
log("Tracking: retryAttempt reset to 0");
}
/** Update lastValidFixTime */
lastValidFixTime = System.currentTimeMillis();
log("Tracking: lastValidFixTime updated.");
/** Trigger events via SimpleLocationListener */
if(bbLocation.getGPSMode()==GPSInfo.GPS_MODE_AUTONOMOUS){
simpleLocationListener.locationEvent(SimpleLocationListener.EVENT_GPS_LOCATION, bbLocation);
log("Tracking: Location delivered to SimpleLocationListener as EVENT_GPS_LOCATION");
}
//#ifdef BlackBerrySDK5.0.0
else if(bbLocation.getGPSMode()==GPSInfo.GPS_MODE_CELLSITE){
simpleLocationListener.locationEvent(SimpleLocationListener.EVENT_CELL_GEOLOCATION, bbLocation);
log("Tracking: Location delivered to SimpleLocationListener as EVENT_CELL_GEOLOCATION");
}
//#endif
//#ifdef BlackBerrySDK6.0.0
else if(bbLocation.getGPSMode()==LocationInfo.GEOLOCATION_MODE_CELL){
simpleLocationListener.locationEvent(SimpleLocationListener.EVENT_CELL_GEOLOCATION, bbLocation);
log("Tracking: Location delivered to SimpleLocationListener as EVENT_CELL_GEOLOCATION");
} else if(bbLocation.getGPSMode()==LocationInfo.GEOLOCATION_MODE_WLAN){
simpleLocationListener.locationEvent(SimpleLocationListener.EVENT_WLAN_GEOLOCATION, bbLocation);
log("Tracking: Location delivered to SimpleLocationListener as EVENT_WLAN_GEOLOCATION");
}
//#endif
else{ // This should not occur