Код маркера при обновлении оси
Проверьте, существует ли маркер:
Код: Выделить всё
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)
}
Код: Выделить всё
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)
Необходимо показывать только один маркер. с точными координатами. Необходимо избегать отображения дубликатов маркеров при обновлении оси
Подробнее здесь: https://stackoverflow.com/questions/787 ... oordinates
Мобильная версия