コード例 #1
0
  @Override
  public void onLocationChanged(Location location) {
    lastLocation = location;
    if (lastLocation != null) {
      latitude = lastLocation.getLatitude();
      longitude = lastLocation.getLongitude();
    }

    for (LocationUpdateListener locationUpdateListener : locationUpdateListeners) {
      locationUpdateListener.onLocationUpdate(location);
    }
  }
コード例 #2
0
 public void onLocationUpdate(Location oldLoc, long oldTime, Location newLoc, long newTime) {
   // We should update only if there is no last location, the provider is the same, or the provider
   // is more accurate, or the old location is stale
   if (lastLoc == null
       || lastLoc.getProvider().equals(newLoc.getProvider())
       || newLoc.getProvider().equals(LocationManager.GPS_PROVIDER)
       || newTime - lastTime > 5 * 60 * 1000) {
     if (listener != null) {
       listener.onLocationUpdate(lastLoc, lastTime, newLoc, newTime);
     }
     lastLoc = newLoc;
     lastTime = newTime;
   }
 }