private static String DB_PATH = "/data/data/com.pokemongo.pokemon.database/databases/"; public static final String DB_NAME = "coordinate"; private static final int SCHEMA = 1; // версия базы данных
There are 2 fields:
private double mMyLatitude = 0; private double mMyLongitude = 0;
DB created in sqllite database and put in folder asset. I get all the records in the database:
@Override protected void onResume() { super.onResume(); try { sqlHelper.open(); userCursor = sqlHelper.database.rawQuery("select * from " + DatabaseHelper.DB_NAME, null); } catch (SQLException ex) { Toast.makeText(getApplicationContext(), "Ошибка открытия БД", Toast.LENGTH_SHORT) .show(); } }
1) I suppose that you need to create a cursor1 in which a value is selected randomly from the latitude field and assigned to mMyLatitude 2) as well, cursor2 select the longitude field and output the second value to this variable mMyLongitude
Tried to make a request for the first item:
private void randomCoordinate() { Cursor c = sqlHelper.database.query(DatabaseHelper.DB_NAME + " ORDER BY RANDOM() LIMIT 1", new String[] { DatabaseHelper.LATITUDE }, null, null, null, null, null); }
Request for item 2:
Cursor cLongitude = sqlHelper.database.query(DatabaseHelper.DB_NAME + " ORDER BY RANDOM() LIMIT 1", new String[] { DatabaseHelper.LONGITUDE }, null, null, null, null, null);
Coordinates are stored in the database, which I will later map to