`Showing 2 marker one with exact coordinates given and one marker at another location where coordinates may be of previous location not specified in current condition.The marker moves according to the coordinates getting from socket.The original marker with coordinates is moving and other showing in another location staying idle.How to fix to remove the duplicate marker not moving.
Marker Code on axis update
Check if the marker already exists:
if (currentBusMarker != null) {
// If it exists, update its position
currentBusMarker!!.position = latLng
} else {
// If it doesn't exist, create a new marker
val mo = MarkerOptions()
.position(latLng)
.title(getString(R.string.current_bus_location))
.icon(currentMarker)
currentBusMarker = mGoogleMap.addMarker(mo)
}
Code for the first initialization of the marker:
if (currentBusMarker != null) {
// If the marker already exists, make it invisible and remove it
currentBusMarker!!.isVisible = false
currentBusMarker!!.remove()
currentBusMarker = null
}
// Create a new marker with the updated position
val mo = MarkerOptions()
.position(
LatLng(
mCurrentStudentActiveRoute!!.lastLatLng.lat,
mCurrentStudentActiveRoute!!.lastLatLng.lng
)
)
.title(getString(R.string.current_bus_location))
.icon(currentMarker)
currentBusMarker = mGoogleMap.addMarker(mo)
Need to show only one marker with exact coordinates.Nee to avoid duplicate marker showing on axis updateenter image description here
Need to show only one marker with exact coordinates.Nee to avoid duplicate marker showing on axis update
Jino Satheesan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.