Good afternoon! I was already googling to know if there is any way to add a bookmark to a map without having to reload onMapReady.
This is what I tried:
With the following code I execute Alerts
which is a WS that is returning me a series of Lat / Long positions every 5 seconds
public void viewAlertas() {
AppLog.Log("", "refresmap");
scheduleTaskExecutor = Executors.newScheduledThreadPool(0);
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Alerts(); }
});
}
}, 0, 5, TimeUnit.SECONDS);
}
I have the positions in a list called coords and I go through that list to paint the marker
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
AppLog.Log("", "ResponseAlert2 :" + coords);
for (int i = 0; i < coords.size(); i++) {
map.addMarker(new MarkerOptions()
.position(new LatLng(coords.get(i).latitude,coords.get(i).longitude))
.title(mylistnombre.get(i))
.snippet(myIdAlertWalker.get(i)));
AppLog.Log("Marker", "Punto " + coords);
}
double latitudeInicial= Double.parseDouble(TrakingApplication.preferenceHelper.getLatWalker());
double longitudeInicial= Double.parseDouble(TrakingApplication.preferenceHelper.getLonWalker());
AppLog.Log("Marker","Punto "+ latitudeInicial + " " + longitudeInicial);
// Cámara
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitudeInicial, longitudeInicial),13));
// Eventos
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
TrakingApplication.preferenceHelper.putIdAlertWalker(marker.getSnippet());
Intent intent = new Intent(getActivity(), Polyline.class);
startActivity(intent);
}
});
}
When you paint the markers for the first time and after 5 seconds you run again Alerts
you need to refresh the map, try
getFragmentManager().beginTransaction().detach(this).attach(this).commit();
Someone will have an idea of how it is done and could help me.
Thank you.