I am developing an Android application where some users open the same action from their devices. There is a map in this action, and when users open this action from their devices, their location coordinates are retrieved from Firebase, and a marker based on these coordinates is displayed on the map.
Here is my code:
acceptingUserReference.child(requestID).child(key).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
final Map<String, String> newAcceptedUser = (Map<String, String>) dataSnapshot.getValue();
nameOfP.add(newAcceptedUser.get("pName"));
cLatP.add(newAcceptedUser.get("currentLat").trim());
cLngP.add(newAcceptedUser.get("currentLng").trim());
addMarkers();
mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setMapToolbarEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.setMaxZoomPreference(19.0f); mMap.setMyLocationEnabled(true);
}
});
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Here's the addMarkers()method:
public void addMarkers() {
mMap.clear();
venueMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(venueLat), Double.parseDouble(venueLng)));
markersList.add(venueMarker);
for (int i = 0; i < nameOfP.size(); i++) {
p = mMap.addMarker(new MarkerOptions().position(new LatLng(Double.valueOf(cLatP.get(i)), Double.valueOf(cLngP.get(i)))).title(nameOfP.get(i).trim()).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
markersList.add(pMarker);
}
}
Here onLocationChanged():
@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
currentLtAU = mCurrentLocation.getLatitude();
currentLnAU = mCurrentLocation.getLongitude();
}
Users move to a specific location.
I want to move the corresponding markers to a new place when users move so that everyone can see where each and everyone is. Please help me sort it out.