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

    1 answer 1

     //создадим два ArrayList ArrayList<Double> latitudesAr = new ArrayList<Double>(); ArrayList<Double> longitudesAr = new ArrayList<Double>(); //заполняем их соответсвенно значениями double из БД if(cLatitude != null) { while(cLatitude.moveToNext){ latitudesAr.add(cLatitude.getDouble(cLatitude.getColomnIndex(DatabaseHelper.LATITUDE))); } } if(cLongitude != null) { while(cLongitude.moveToNext){ longitudesAr.add(cLatitude.getDouble(cLatitude.getColomnIndex(DatabaseHelper.LONGITUDE))); } } //получаем рандомно выбранные индексы Random r = new Random(); int indexLatitude = r.nextInt(latitudesAr.size()); int indexLongitude = r.nextInt(longitudeaAr.size()); //присваиваем переменным mMyLatitude = latitudesAr.get(indexLatitude); mMyLingitude = longitudesAr.get(indexLongitude); 
    • and call this method where it will be right? - upward