set individual information to each custom marker

Hi community,

I have a problem with an array of MKAnnotationViews that are customized, in which I want to display the information for each marker individually, such as its title or its description that contains that marker, I don't know if it opens any way to do it.

I leave my code below:

  func setUpAllThePins(allLogos:[String],allLongitudesAndLatitudes:[CLLocationCoordinate2D],kmDouble:[Double],streets:[String],alcaldia:[String],calificacion:[Int],titulos:[String]){

        

                

        imagenes = allLogos.compactMap{ link->UIImage? in

            guard let url = URL(string: link) else {return nil}

        guard let imageData = try? Data(contentsOf: url) else {return nil}

            return UIImage(data: imageData)

                   }

   

        let annotations = zip(allLongitudesAndLatitudes, imagenes)

        .map { (coordinate, allLogos) -> myAnnotation in

            let annotation = myAnnotation(title: "", subtitle: "", coordinate: coordinate, localImage: allLogos)

            return
annotation

                }

  

        if let oldArray = annotations as? [MKAnnotation]{

            for i in oldArray{

                mapView.addAnnotation(i)

            }

           

        }

    

    }
I want to ask you a few things:
  • Please use the Code block feature of this site (shown as < >)

  • What is myAnnotation? Is it a type? In Swift, type names should start with Capital letter

  • How are you adding MKAnnotations to your MKMapView?

  • How are you creating MKAnnotationView from MKAnnotation?

Code will be easier to analyse when formatted and pasted as Paste and Match Style and without useless blank lines

Code Block
func setUpAllThePins(allLogos:[String], allLongitudesAndLatitudes:[CLLocationCoordinate2D], kmDouble:[Double], streets:[String], alcaldia:[String], calificacion:[Int], titulos:[String]) {
imagenes = allLogos.compactMap { link->UIImage? in
guard let url = URL(string: link) else {return nil }
guard let imageData = try? Data(contentsOf: url) else {return nil }
return UIImage(data: imageData)
}
let annotations = zip(allLongitudesAndLatitudes, imagenes)
.map { (coordinate, allLogos) -> myAnnotation in
let annotation = myAnnotation(title: "", subtitle: "", coordinate: coordinate, localImage: allLogos)
return annotation
}
if let oldArray = annotations as? [MKAnnotation] {
for i in oldArray{
mapView.addAnnotation(i)
}
}
}


I have a problem with an array of MKAnnotationViews that are customized, in which I want to display the information for each marker individually, such as its title or its description that contains that marker, I don't know if it opens any way to do it.

  • What is exactly the problem ?

  • What is the information you want to display ? titles ?

  • you pass nothing in annotation on line 11. Why ?

  • What should be title and subtitle ?

set individual information to each custom marker
 
 
Q