void Adi
void Adi

Reputation: 318

Google map markers are disappearing instantly. How to make a marker remain constant?

I am adding markers on my map by fetching user locations stored in the remote server. The locations are displayed but within 3 seconds, the marker disappears. Any solution to this?? Below is my complete code.

protected void onPostExecute(Void result) 
{           
        super.onPostExecute(result);
        for(Users u:locList)
        {


            MarkerOptions markerOptions = new MarkerOptions();
            double latitude1 = u.getLatitude();
            double longitude1 = u.getLongitude();



            LatLng latLng1 = new LatLng(latitude1, longitude1);

            // Animating to the touched position                                
            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng1));   

            if(userMarker!=null) userMarker.remove();

            markerOptions = new MarkerOptions().position(new LatLng(latitude1, longitude1)).title(latLng1.toString());

            // adding marker
            userMarker = mGoogleMap.addMarker(markerOptions);
            //userMarker.setVisible(true);




            // Placing a marker on the touched position
            mGoogleMap.addMarker(markerOptions); 

            markerOptions.visible(true);
     }

}

Upvotes: 1

Views: 2049

Answers (3)

Daniel Odorizzi
Daniel Odorizzi

Reputation: 1

I fixed the same issue by commenting out map.clear.

Upvotes: 0

Sourabh Saldi
Sourabh Saldi

Reputation: 3587

Check your code. If you're using map.clear(), remove it.

Upvotes: 3

Piyush
Piyush

Reputation: 18923

remove

userMarker.remove();

from your code...

Upvotes: 1

Related Questions