package edu.berkeley.eecs.cfc_tracker.wrapper;

import android.location.Location;

import java.text.SimpleDateFormat;

/**
 * Created by shankari on 8/30/15.
 */
public class SimpleLocation {
    public double getLatitude() {
        return latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public double getTs() {
        return ts;
    }

    private double latitude;
    private double longitude;
    private double altitude;

    private double ts;
    private String fmt_time;
    private long elapsedRealtimeNanos;

    private float sensed_speed;
    private float accuracy;
    private float bearing;

    private String provider;
    private final String filter = "time";

    /*
     * No-arg constructor to use with gson.
     * If this works, consider switching to a custom serializer instead.
     */
    public SimpleLocation() {}

    public SimpleLocation(Location loc) {
        latitude = loc.getLatitude();
        longitude = loc.getLongitude();
        altitude = loc.getAltitude();

        ts = ((double)loc.getTime())/1000;
        // NOTE: There is no ISO format datetime shortcut on java.
        // This will probably return values that are not in the ISO format.
        // but that's OK because we will fix it on the server
        fmt_time = SimpleDateFormat.getDateTimeInstance().format(ts);
        elapsedRealtimeNanos = loc.getElapsedRealtimeNanos();

        sensed_speed = loc.getSpeed();
        accuracy = loc.getAccuracy();
        bearing = loc.getBearing();
    }

    public float distanceTo(SimpleLocation dest) {
        float[] results = new float[1];
        Location.distanceBetween(latitude, longitude, dest.getLatitude(), dest.getLongitude(), results);
        return results[0];
    }
}

@@ -1350,18 +1350,29 @@
 .format(
-ts
+loc.getTime()
 );%0A     

Fix the formatting of the timestamp for location entries