public static Location getLastKnownLocation ( final LocationManager pLocationManager ) { if ( pLocationManager == null ) { return null ; } final Location gpsLocation = getLastKnownLocation ( pLocationManager , LocationManager . GPS_PROVIDER ) ; final Location networkLocation = getLastKnownLocation ( pLocationManager , LocationManager . NETWORK_PROVIDER ) ; if ( gpsLocation == null ) { return networkLocation ; } else if ( networkLocation == null ) { return gpsLocation ; } else { // both are non-null - use the most recent if ( networkLocation . getTime ( ) > gpsLocation . getTime ( ) + Configuration . getInstance ( ) . getGpsWaitTime ( ) ) { return networkLocation ; } else { return gpsLocation ; } } }
Get the most recent location from the GPS or Network provider .