MKAnnotationView for MapKit does not work in Kotlin Multiplatform iOS #4497
-
Hi, I have tried to change the look of Annotation markers on KMP but any changes are completely ignored. This includes trying to change the colour of the default marker or trying to change the image (which is what I really want to do). Everything ends up just displaying the default marker (which is clickable and animates and expands). The marker title and subtitle also work (although these are part of MKPointAnnotation, so I would expect them to work). I have tried changing the colour in the ImageViewer example in this repository:
I've also been trying in my own project, by changing the image; all to no avail:
Is there something I am doing wrong, or is this just broken? It would appear to be the latter which is a shame as it makes using maps completely unusable for me as I need to be able to show different markers for different things. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To answer my own question - as I was not familiar with how the annotations work as I'm from the Google Maps world, the map requires a delegate in order to show custom markers. And I thought Google Maps was weird. But I digress. Bizarrely many of the functions in the delegate are overloaded with the same name and parameter types, although different parameter names. This produces an error in the IDE because of function ambiguity, but the code still compiles and runs. This threw me for a long time. If anyone alights on this in search of an answer, you need a delegate for the map:
and:
to assign the delegate. BTW, in the code above I'm creating everything as a test - you will need to actually work out what view is needed from what is passed to the function. Also, .toImageBytes() is my own function for converting a ByteArray from Kotlin shared resources to a UIImage. You could of course use an image in the ioS Bundle (commented lines). |
Beta Was this translation helpful? Give feedback.
To answer my own question - as I was not familiar with how the annotations work as I'm from the Google Maps world, the map requires a delegate in order to show custom markers. And I thought Google Maps was weird. But I digress.
Bizarrely many of the functions in the delegate are overloaded with the same name and parameter types, although different parameter names. This produces an error in the IDE because of function ambiguity, but the code still compiles and runs. This threw me for a long time.
If anyone alights on this in search of an answer, you need a delegate for the map: