Code example for Location

Methods: getAccuracygetLatitudegetLongitudegetProviderhasAccuracy

0
    final long now = System.currentTimeMillis();
     
    if ( location == null ) {
      // bad! 
    } 
    else if ( GPS_PROVIDER.equals( location.getProvider() ) ) {
      if ( satCount > 0 && satCount < 3 ) {
        if ( satCountLowTime == null ) {
          satCountLowTime = now;
        } 
      } 
      else { 
        // plenty of sats 
        satCountLowTime = null;
      } 
      boolean gpsLost = satCountLowTime != null && (now - satCountLowTime) > GPS_TIMEOUT;
      gpsLost |= now - lastLocationTime > GPS_TIMEOUT;
      gpsLost |= horribleGps(location);
      retval = ! gpsLost;
    } 
    else if ( NETWORK_PROVIDER.equals( location.getProvider() ) ) {
      boolean gpsLost = now - lastNetworkLocationTime > NET_LOC_TIMEOUT;
      gpsLost |= horribleGps(location);      
      retval = ! gpsLost;
    } 
     
    return retval;
  } 
   
  private boolean horribleGps(final Location location) {
    // try to protect against some horrible gps's out there 
    boolean horrible = false;
    // check if accuracy is under 10 miles 
    horrible |= location.hasAccuracy() && location.getAccuracy() > 16000;
    horrible |= location.getLatitude() < -90 || location.getLatitude() > 90;
    horrible |= location.getLongitude() < -180 || location.getLongitude() > 180;
    return horrible;
  } 
   
  public int getSatCount() { 
    int satCount = 0;