Move all markers on the map to their updated / new current location periodically when users move

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();

                                            //Check map is loaded
                                            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.

+1
3

addMarker setPosition ( addMarker).

0

, . , , , :

http://pastebin.com/9qq484Fz

, ! ( , )

0

1. onLocationChanged , .

Firebase onLocationChanged, .

Note : use geofire to update the user's location and see this answer .

@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
currentLtAU = mCurrentLocation.getLatitude();
currentLnAU = mCurrentLocation.getLongitude();
}

2. call the acceptingUserReference.child(requestID)code when successfully updating the user's location toFirebase

0
source

All Articles