Aqui tenho a parte do código da minha MainActivity.java onde chamo a latitude e a longitude para serem exibidos os locais no mapa:
mPlaces = (Place[]) savedInstanceState.getParcelableArray("places");
for(int i=0;i<mPlaces.length;i++){
LatLng point = new LatLng(Double.parseDouble(mPlaces[i].mLat),
Double.parseDouble(mPlaces[i].mLng));
Marker m = drawMarker(point,UNDEFINED_COLOR);
mHMReference.put(m.getId(), mPlaces[i]);
}
Esta é a classe MySQLiteOpenHelper.java
public class MySQLiteHelper extends SQLiteOpenHelper {
public static final String TABELA_DESCRICAO = "descricao";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_COMENTARIO = "comentario";
public static final String COLUMN_LAT = "lat";
public static final String COLUMN_LNG = "lng";
private static final String DATABASE_NAME = "descricao.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABELA_DESCRICAO + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMENTARIO
+ " text not null)" +
COLUMN_LAT + "double" + COLUMN_LNG + "double"
+ COLUMN_COMENTARIO + "text no null";
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase basedados) {
basedados.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABELA_DESCRICAO);
onCreate(db);
}
}
Esta é a classe DescricaoDAO.java que faz a interface entre a classe Descricao.java e MySQLiteOpenHelper.java
public class DescricaoDAO {
public class DescricaoDAO {
// Database fields
private SQLiteDatabase database;
private MySQLiteHelper dbHelper;
private String[] allColumns = { MySQLiteHelper.COLUMN_ID, MySQLiteHelper.COLUMN_LAT, MySQLiteHelper.COLUMN_LNG,
MySQLiteHelper.COLUMN_COMENTARIO };
public DescricaoDAO(Context context) {
dbHelper = new MySQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public Descricao createComment(String comentario) {
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_COMENTARIO, comentario);
long insertId = database.insert(MySQLiteHelper.TABELA_DESCRICAO, null,
values);
Cursor cursor = database.query(MySQLiteHelper.TABELA_DESCRICAO,
allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
Descricao newComment = cursorToComment(cursor);
cursor.close();
return newComment;
}
public void deleteComment(Descricao comentario) {
long id = comentario.getId();
System.out.println("Comment deleted with id: " + id);
database.delete(MySQLiteHelper.TABELA_DESCRICAO, MySQLiteHelper.COLUMN_ID
+ " = " + id, null);
}
public List<Descricao> getAllComments() {
List<Descricao> descricao = new ArrayList<Descricao>();
Cursor cursor = database.query(MySQLiteHelper.TABELA_DESCRICAO,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Descricao comentario = cursorToComment(cursor);
descricao.add(comentario);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return descricao;
}
private Descricao cursorToComment(Cursor cursor) {
Descricao comentario = new Descricao();
comentario.setId(cursor.getLong(0));
comentario.setComentario(cursor.getString(1));
return comentario;
}
}