@Override
  public void bestLocationChanged(Location oldLocation, Location newLocation) {
    long currentTime = System.currentTimeMillis();

    LocationController cont = LocationController.getInstance(this.context);

    Log.d("HistoryController", "Best location updated! (hasGPSLock: " + cont.hasGPSLock() + ")");

    if (cont.hasGPSLock()) {
      if (stationaryLocationStart == null) {
        stationaryLocationStart = newLocation;
        stationaryLocationEnd = newLocation;
        stationaryLocationStartTime = currentTime;
      } else {
        Log.d(
            "HistoryController",
            "Distance from stationary point: " + stationaryLocationStart.distanceTo(newLocation));

        if (stationaryLocationStart.distanceTo(newLocation) < STATIONARY_RADIUS) {
          Log.d("HistoryController", "New location was within radius");

          stationaryLocationEnd = newLocation;
        } else {
          Log.d(
              "HistoryController",
              "New location out of radius (time delta: "
                  + (currentTime - stationaryLocationStartTime)
                  + ")");

          if (currentTime - stationaryLocationStartTime > STATIONARY_TIME) {
            Log.d(
                "HistoryController",
                "Stayed in previous location long enough, recording to history");

            HistoryItem item = new HistoryItem();
            item.date = stationaryLocationStartTime;
            item.elapsed_time = currentTime - stationaryLocationStartTime;
            item.latitude = stationaryLocationStart.getLatitude();
            item.longitude = stationaryLocationStart.getLongitude();

            historyStorage.put(item);

            //
            // Notify listeners
            //

            synchronized (this) {
              for (HistoryListener l : this.listeners) l.onNewHistoryItem(item);
            }
          }

          stationaryLocationStart = newLocation;
          stationaryLocationEnd = newLocation;
          stationaryLocationStartTime = currentTime;
        }
      }
    }
  }