Пример #1
0
  /** flush cache */
  public void flushCache() {
    Iterator<Long> iterator = locationCache.keySet().iterator();
    while (iterator.hasNext()) {
      Long timeMillis = iterator.next();
      Location location = locationCache.get(timeMillis);
      if (archiver.add(location, timeMillis)) {
        Helper.Logger.i(
            String.format(
                "Location(%f, %f) has been saved into database.",
                location.getLatitude(), location.getLongitude()));
      }
    }

    locationCache.clear();
  }
Пример #2
0
  @Override
  public void onLocationChanged(Location location) {
    // Save fitted location into database
    if (filter(location)) {
      locationCache.put(System.currentTimeMillis(), location);
      if (locationCache.size() > CACHE_SIZE) {
        flushCache();
      }

      // 计算动态路径
      this.meta = archiver.getMeta();
      if (meta != null) {
        meta.setRawDistance();
      }
    }
  }