public long add(Waypoint w) {
    if (w.time == 0) w.time = System.currentTimeMillis();
    long out = db.add(w);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (this.nextWaypointName().equals(w.name)) {
      int num = prefs.getInt(KEY_WAYPOINT_NUMBER, 1);
      prefs.edit().putInt(KEY_WAYPOINT_NUMBER, num + 1).commit();
    }

    if (map != null && out > 0) refreshMarkers();
    Log.i(TAG, "adding waypoint " + out);
    return out;
  }
 private static Waypoint waypointFrom(Cursor c) {
   Waypoint w = new Waypoint();
   w.id = c.getLong(0);
   w.lat = c.getDouble(1);
   w.lon = c.getDouble(2);
   w.altitude = c.getDouble(3);
   w.name = c.getString(4);
   w.description = c.getString(5);
   w.icon = c.getString(6);
   w.iconType = c.getString(7);
   w.temporary = c.getInt(8) == 1;
   w.time = c.getLong(9);
   w.category = c.getString(10);
   return w;
 }