The application has a map with markers, the markers' visibiliy is set to false, i want the markers to show up when the device is at a certain range of any marker, as a result setting that marker to be visible. I assume it has something to do with the method location.distanceTo(anotherLocation) and then show location if distance to is less than a pre-defined distance in meters. But i am failing at making this work.
This is the method to add the markers onto the map from an arraylist.
for(MyLatLngData location : locations){
mMap.addMarker(new MarkerOptions()
.position(location.getLatLng())
.title(location.getTitle())
.visible(false));
}
Here is how i store the data in arrays from a database using a MyLatLngData object.
void storeDataInArrays() {
Cursor cursor = databaseHelper.readAllData();
if (cursor.getCount() == 0) {
Toast.makeText(this, "No data", Toast.LENGTH_SHORT).show();
} else {
while (cursor.moveToNext()) {
// remove all previous list adds.
locations.add(new MyLatLngData(
cursor.getString(0),
cursor.getString(1),
cursor.getDouble(2),
cursor.getDouble(3)));
}
}
}
How do i take account of all the locations using the distanceTo method and how do i set the first location to be the fusedLocationProvider's current location.
As an addition i would like the markers' states to be saved so that the ones that are set visible will stay visible.
Any thanks are well appreciated and i hope that someone could help with this as my programming skills are still being polished.