package xyz.whereuat.whereuat;

import android.content.ContentValues;
import android.content.Context;
import android.location.Location;

import xyz.whereuat.whereuat.db.command.InsertCommand;
import xyz.whereuat.whereuat.db.entry.KeyLocationEntry;

/**
 * Created by kangp3 on 4/10/16.
 */
public class KeyLocationUtils {
    private static final String TAG = "KeyLocObj";

    public static boolean nameIsValid(String name) {
        return name != null && name.length() > 0;
    }

    public static boolean locIsValid(Location loc) {
        return loc != null;
    }

    public static InsertCommand buildInsertCommand(Context context, String name, double latitude,
                                                   double longitude) {
        ContentValues values = new ContentValues();
        values.put(KeyLocationEntry.COLUMN_NAME, name);
        values.put(KeyLocationEntry.COLUMN_LATITUDE, latitude);
        values.put(KeyLocationEntry.COLUMN_LONGITUDE, longitude);

        return new InsertCommand(context, KeyLocationEntry.TABLE_NAME, null, values);
    }
}

@@ -95,16 +95,48 @@
 ontext;%0A
+import android.database.Cursor;%0A
 import a
@@ -589,32 +589,920 @@
 != null;%0A    %7D%0A%0A
+    public static String getNearestLoc(Cursor c, Location origin) throws IllegalArgumentException %7B%0A        String nearest = null;%0A        double nearest_dist = Double.MAX_VALUE;%0A%0A        c.moveToFirst();%0A        while(c.moveToNext()) %7B%0A            double longitude = c.getDouble(c.getColumnIndexOrThrow(%0A                    KeyLocationEntry.COLUMN_LONGITUDE));%0A            double latitude = c.getDouble(c.getColumnIndexOrThrow(%0A                    KeyLocationEntry.COLUMN_LATITUDE));%0A%0A            Location loc = new Location(%22%22);%0A            loc.setLongitude(longitude);%0A            loc.setLatitude(latitude);%0A%0A            double dist = loc.distanceTo(origin);%0A            if (dist %3C nearest_dist) %7B%0A                nearest = c.getString(c.getColumnIndexOrThrow(KeyLocationEntry.COLUMN_NAME));%0A                nearest_dist = dist;%0A            %7D%0A        %7D%0A%0A        return nearest;%0A    %7D%0A%0A
     public stati

Add nearest loc utility function