• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Updating Multiple Marker Position Android Google Maps

lastpeony

Lurker
I am pulling marker data from db and placing them on map.What i am trying to do is updating their positions on map when it is changed. Code below is doing its job for when there is 1 marker.I know its wrong for multiple markers.What should i do for multiple markers ?
Code:
Marker otherplayermarker;
    mydb.child("map").child("players").addValueEventListener(new ValueEventListener() {
            @override
            public void onDataChange(DataSnapshot dataSnapshot) {
                HashMap<String,AvatarObject> players= new HashMap();
                for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
                    players.put(childSnapshot.getKey(), childSnapshot.getValue(AvatarObject.class));
                }
                players.remove(username); //nvm this
                for (Map.Entry<String, AvatarObject> entry : players.entrySet()) {
                    Log.d("asd","Key = " + entry.getKey() + ", Latitude = " + entry.getValue().getLatitude()+"Longitude = " + entry.getValue().getLongitude());

                    LatLng latlngotherplayer;
                    latlngotherplayer = new LatLng(entry.getValue().getLatitude(), entry.getValue().getLongitude());


                    if (otherplayermarker == null) {
                        MarkerOptions otherplayermarkeroptions = new MarkerOptions();
                        otherplayermarkeroptions.position(latlngotherplayer);
                        otherplayermarkeroptions.title(entry.getValue().getAvatar());
                        otherplayermarkeroptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.petyravatar));
                        Marker otherplayermarker = googleMap.addMarker(otherplayermarkeroptions);
                        MarkerAnimation.animateMarkerToICS(otherplayermarker, latlngotherplayer, new LatLngInterpolator.Spherical());

                    }else{
                        MarkerAnimation.animateMarkerToICS(otherplayermarker, latlngotherplayer, new LatLngInterpolator.Spherical());


                    }

                }




            }

            @override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
 
Back
Top Bottom