Android Open Source - yousense-android-tracker Location Fix






From Project

Back to project page yousense-android-tracker.

License

The source code is released under:

Energy-efficent motion and location tracker for Android. Based on Mattias's power and tracking work. I plan to release it as GPL, once I have a paper published that goes with it. Might also release i...

If you think the Android project yousense-android-tracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.linnap.locationtracker.gps;
//from  ww  w .jav  a2  s  .c om
import android.location.Location;
import android.os.Bundle;

/**
 * Location class that can be nicely serialized with Gson.
 */
public class LocationFix {
  public String provider;
  public long time;
  public double lat;
  public double lng;
  public Float accuracy;
  public Double altitude;
  public Float bearing;
  public Float speed;
  
  public LocationFix() {    
  }
  
  public LocationFix(Location location) {
    this.provider = location.getProvider();
    this.time = location.getTime();
    this.lat = location.getLatitude();
    this.lng = location.getLongitude();
    this.accuracy = location.hasAccuracy() ? location.getAccuracy() : null;
    this.altitude = location.hasAltitude() ? location.getAltitude() : null;
    this.bearing = location.hasBearing() ? location.getBearing() : null;
    this.speed = location.hasSpeed() ? location.getSpeed() : null;
  }
  
  public LocationFix(Bundle b) {
    if (b != null) {
      this.provider = b.getString("provider");
      this.time = b.getLong("time", 0);
      this.lat = b.getDouble("lat", 0.0);
      this.lng = b.getDouble("lng", 0.0);
      if (b.containsKey("accuracy"))
        this.accuracy = b.getFloat("accuracy", 0.0f);
      if (b.containsKey("altitude"))
        this.altitude = b.getDouble("altitude", 0.0);
      if (b.containsKey("bearing"))
        this.bearing = b.getFloat("bearing", 0.0f);
      if (b.containsKey("speed"))
        this.speed = b.getFloat("speed", 0.0f);
    }
  }

  @Override
  public String toString() {
    return String.format("%.5f north, %.5f east at %d", lat, lng, time);
  }
  
  public Bundle toBundle() {
    Bundle b = new Bundle();
    b.putString("provider",  provider);
    b.putLong("time", time);
    b.putDouble("lat", lat);
    b.putDouble("lng", lng);
    if (accuracy != null)
      b.putFloat("accuracy", accuracy.floatValue());
    if (altitude != null)
      b.putDouble("altitude", altitude.doubleValue());
    if (bearing != null)
      b.putFloat("bearing", bearing.floatValue());
    if (speed != null)
      b.putFloat("speed", speed.floatValue());    
    return b;
  }
}




Java Source Code List

com.linnap.locationtracker.EventBindings.java
com.linnap.locationtracker.ExpectedState.java
com.linnap.locationtracker.LocationTrackerService.java
com.linnap.locationtracker.SensorConfig.java
com.linnap.locationtracker.Sets.java
com.linnap.locationtracker.StateChange.java
com.linnap.locationtracker.gps.DistanceCycledGps.java
com.linnap.locationtracker.gps.GpsHistory.java
com.linnap.locationtracker.gps.LocationFix.java
com.linnap.locationtracker.movement.AccelerometerData.java
com.linnap.locationtracker.movement.BooleanState.java
com.linnap.locationtracker.movement.DutyCycledAccelerometer.java
com.linnap.locationtracker.movement.SmallMovement.java
com.linnap.locationtracker.movement.StatsAccumulator.java
com.linnap.locationtracker.schedule.SensorScheduler.java
com.linnap.locationtracker.wifi.ScanResultsData.java
com.linnap.locationtracker.wifi.ScanStartedData.java
com.linnap.locationtracker.wifi.TimeoutScan.java
com.linnap.locationtracker.wifi.WifiFingerprint.java
com.linnap.locationtracker.wifi.WifiPlaceChange.java