TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Not Able To Customize MKMapView Annotations

Forums > SwiftUI

@ASH  

I'm using the MKMapViewDelegate methods with SwiftUI and adding annotations mostly work as long as there are no image customizations. If I try to change the color or flip the image only the standard image is shown. Using the debugger I can see that the annotationView.image in memory is correct (when parent.routeMeta.headingLeftToRight is false), yet the map displays the standard image. Any suggestions?

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
              let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "TempAnnotationView")
              annotationView.canShowCallout = true
              annotationView.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)

              if annotation.title == "Center" {
                  let configuration2 = UIImage.SymbolConfiguration(pointSize: 20, weight: .thin, scale: .large)
                  let stdImage = UIImage(systemName: "star.circle", withConfiguration: configuration2)
                  let flippedImage = stdImage.withHorizontallyFlippedOrientation()
                  if parent.routeMeta.headingLeftToRight {
                      annotationView.image = stdImage
                  } else {
                      annotationView.image = flippedImage.withTintColor(.systemRed, renderingMode: .alwaysOriginal)
                  }
                }
              return annotationView
          }

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.