Code example for Location

Methods: distanceTogetAccuracygetTime

0
 
    if (network == null) {
      return(gps);
    } 
 
    Location older=(gps.getTime() < network.getTime() ? gps : network);
    Location newer=(gps == older ? network : gps);
 
    // older and less accurate fixes suck 
 
    if (older.getAccuracy() <= newer.getAccuracy()) {
      return(newer);
    } 
 
    // if older is within error radius of newer, assume 
    // not moving and go with older (since has better 
    // accuracy, else would have been caught by previous 
    // condition) 
 
    // ideally, this would really be "if the odds of 
    // the older being within the error radius of the 
    // newer are higher than 50%", taking into account 
    // the older one's accuracy as well -- the 
    // implementation 
    // of this is left as an exercise for the reader 
 
    if (newer.distanceTo(older) < newer.getAccuracy()) {
      return(older);
    } 
 
    // if all else fails, choose the newer one -- the device 
    // is probably moving, and so we are better off with the