When I change the icon of a google maps marker and I activate a ground overlay, the marker is moving when I zoom.
The overlay is an hisorial map as .jpg
As marker icon I use the android vector image baseline_flag (xml)
Here my code:
private lateinit var map: GoogleMap
private lateinit var mapOverlay : GroundOverlay
private val callback = OnMapReadyCallback { googleMap ->
map = googleMap
position = LatLng(latitude, longitude)
map.addMarker(MarkerOptions().position(position).title(place.currentPlace.place).icon(bitMapFromVector(R.drawable.baseline_flag)))
val overlay = GroundOverlayOptions().image(BitmapDescriptorFactory.fromAsset("map.jpg"))
.position(position, width, height)
overlay.bearing(bearing)
mapOverlay = map.addGroundOverlay(overlay)!!
}
private fun bitMapFromVector(vectorResID:Int): BitmapDescriptor {
val vectorDrawable =ContextCompat.getDrawable(requireContext(),vectorResID)
vectorDrawable!!.setBounds(0,0, vectorDrawable.intrinsicWidth,vectorDrawable.intrinsicHeight)
val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth,vectorDrawable.intrinsicHeight,Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
vectorDrawable.draw(canvas)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
The problem occurs only when both groundoverlay and changed maker icon is activated.
I found somewhere the information, that MarkerOptions().anchor()
could help here, but I tried this with different values, it didn’t change anything.