Map Marker icon Overlapped with the new and old icon - Android

Viewed 34

When trying to change the marker icon is overlapped with the old icon. the old icon is still there

for (i in chargingPointOnMapData.indices) {
            position = LatLng(
                chargePointsOnMap[i].lattitude!!.toDouble(),
                chargePointsOnMap[i].longitude!!.toDouble()
            )
            this.googleMap?.addMarker(MarkerOptions()
                    .position(position)
                    .title(markerType)
                    .zIndex(zIndex)
                    .icon(BitmapDescriptorFactory.fromResource(markerIcon))
            )}

 override fun onMapReady(googleMap: GoogleMap) {
   googleMap.setOnMarkerClickListener{
   marker.apply {
      setIcon(BitmapDescriptorFactory.fromResource(R.drawable.test_cp_ac))
   }
}

}

output image

1 Answers

occurs when a marker is inserted twice. Please double-check where and how often you add the marking. if not, call Google Maps. each time before adding,

googleMap?.clear()
Related