I am displaying a Google map in an Android application with two markers. On the onMapReady method everything works well, the map renders and the markers appear with the relevant bitmaps and information.
I have even implemented a zoom boundary using the CameraUpdateFactory() function with LatLngBounds. Again, up to this point, everything works well and as expected. Here's the snippet:
override fun onMapReady(googleMap: GoogleMap?) {
myGoogleMap = googleMap
// myMapMarker is a global variable of type MarkerOptions
// the options are set only once here and never changed elsewhere in the code
myMapMarker = MarkerOptions()
.position(LatLng(34.1478, 118.1445))
.title("My Location")
.snippet("Description of my location...")
.icon(BitmapDescriptorFactory.fromBitmap(pinBitmap))
// myMapMarker is added to the map only once here and
// never removed or added again elsewhere in the code
myGoogleMap?.addMarker(myMapMarker)
}
However, when I try to reposition the marker using the marker setPosition function (just position in Kotlin), the marker position is changed but the pin remains in its original position, with the info-window still functional. I know that the marker position is updated because the next call to the zoom to bounds function zooms in to the new boundaries.
// only one attempt is made to move myMapMarker here
// the marker location is successfully changed
// >>> evidenced by println(myMapMarker?.location)
// the marker icon/pin is not re-positioned
myMapMarker?.position(LatLng(mapData.latitude, mapData.longitude))
I've read that the markers should be re-positioned and not removed & added again. So, is there a missing step in getting the marker to reposition correctly?
I've also tried to downgrade the Google Play Maps API from 17 to 16, but still getting the same results.
TIA.
EDIT: Adding a screenshot to illustrate the issue
The original marker was at 452 Ford Place (the red marker). After performing a setPosition(), the red marker should appear where the blue marker is, but it doesn't. It stays at 452 Ford Place.
myMapMarker
so that the previous marker stays same – Abu Yousuf