The application copies a pre-populated database from the assets folder and from there gets each column's worth of data and stores it in array lists and draws markers onto the map from there on.
Now I need a method that would change the pre-existing data's column's (called "active") value from 0 to 1 if a marker is at a certain range from the device. The method I wrote only adds about 40 new rows of info where the "active" column has a "1" as its data and the rest are NULL but don't affect the previous data.
How can I change the "active" column to 1 on the rows of the right markers' data that are within the range of the device? I hope I wrote it so that you could understand. I roughly know how to change a particular row's column info upon need but since I need to get a particular row that depends on the device's location at the time, then I don't know how to do so.
Databasehelper's method of updating the column so far
public void setActive()
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("active", 1);
db.update(TABLE_NAME, cv, "id= ?",null );
}
Mainactivity, a method that checks if the location is in range. It has an additional method using a timer to check if the location is in range every 10seconds.
fusedLocationProviderClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
Double lat = location.getLatitude();
Double lon = location.getLongitude();
LatLng latlon = new LatLng(lat, lon);
for (MyLatLngData location1 : locations) {
LatLng loc1 = new LatLng(location1.getLatitude(),location1.getLongitude());
if (SphericalUtil.computeDistanceBetween(latlon, loc1) < 1000) {
databaseHelper.setActive();
Thanks in advance.