SwiftUI MKMapView cannot display annotation pins in a loop

I have code to display pin annotations on MapView customized with left, right accessory views. There are three pin annotations and I pass them to the MapView via Binding locationPins, an array of structs. The three Pins are getting displayed with annotation text, But I it not working as expected for the following reasons:

  1. The annotation text captured by label called subtitleView shows the value from the last pin annotation for all the three pins as: “2 Level 1: 120 V”, instead of displaying different values for pin annotations ( please see debug output below)

  2. Debug shows the sequence of methods called. The mapView delegate gets called 3 times. When called each time it is supposed to return with one pin annotation. I know my logic is wrong since I loop inside the mapView delegate three times, whereas ideally I should be looping outside to call mapview delegate and pass one element of the array locationPins. So how to call the delegate and pass only one element of the array locationPins?

  3. Also when mapview displays zooms in on only one pin. I have to physically pan to zoom out and then I see all the three pins. Why is not adjusting the map to show all three pins.
    I need help?
    Code:

    struct ProfileView: View {
    @Environment(.managedObjectContext) private var viewContext
    @Environment(.dismiss) var dismiss
    @State var tracking:MapUserTrackingMode = .follow
    @Environment(.presentationMode) var presentationMode
    @Binding var locationPins: [GpsData.MyEndPt]
    
    
    var body: some View {
     TabView {
         NavigationView {
             ZStack {
                 VStack (alignment: .leading){
                     MapView(locationPins: $locationPins)
                         .ignoresSafeArea()
    
                 }
             }
             .safeAreaInset(edge: .bottom) {
               Color.clear
                 .frame(height: 0)
                 .background(.white)
             }
    
             .toolbar {
                 ToolbarItem(placement: .principal) { // <3>
                     VStack {
                         Text("Profiles").font(.headline)
                     }
                 }
    
             }
         }
     }
    
    }
    
    
    
    struct MapView: UIViewRepresentable {
      @Binding var locationPins: [GpsData.MyEndPt]
     func makeUIView(context: Context) -> MKMapView {
         let view = MKMapView()
         view.delegate = context.coordinator
         return view
     }
    
     func updateUIView(_ uiView: MKMapView, context: Context) {
         print("updateUIView called")
         uiView.mapType = .mutedStandard
         uiView.addAnnotations(self.locationPins)
     }
    
     func makeCoordinator() -> MapViewDelegate{
         print("coordinator called")
         var del = MapViewDelegate()
         del.addEndPoints(endPoints: locationPins)
         return del
     }
    
     class MapViewDelegate: MKMapView, MKMapViewDelegate {
    
         let PINID:String = "MyEndPoint"
         var mylocationPins: [GpsData.MyEndPt] = []
         @State var locationId: String?
         @State var providerType: String?
    
    
         public func addEndPoints(endPoints: [GpsData.MyEndPt]) {
              print("addEndPoints called")
             self.mylocationPins = endPoints
             self.showAnnotations(endPoints, animated: true)
         }
    
         internal func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
             print("mapview delegate called")
             var mPin: MKMarkerAnnotationView? = nil
             var mPins = [MKMarkerAnnotationView]()
             let subtitleView = UILabel()
             subtitleView.font = subtitleView.font.withSize(10)
             subtitleView.numberOfLines = 4
    
             if (mPin == nil ) {
                 mPin = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: PINID)
                 mPin?.canShowCallout = true
             } else{
                 mPin?.annotation = annotation
             }
             mPin?.leftCalloutAccessoryView = nil
             mPin?.rightCalloutAccessoryView = nil
    
                 if let myEndpt = annotation as? GpsData.MyEndPt {
                     if myEndpt.thumbnailUrl != nil {
                         mPin?.leftCalloutAccessoryView = UIButton(frame: CGRect(x: 0, y: 0, width: 55, height: 55) )
                     }
    
                     mPin?.rightCalloutAccessoryView = UIButton(type: UIButton.ButtonType.detailDisclosure)
                     var i: Int = 0
                     for pin in self.mylocationPins {
                         subtitleView.text = "count: "
                         subtitleView.text! += String(i)
                         i += 1
                         print("subtitleView: (subtitleView.text)")
    
                     }
    
                 }
             return mPin!
         }
         //MARK:- delegate method
    
         func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
             DispatchQueue.main.async {
                 if let thumbnailImageButton = view.leftCalloutAccessoryView as? UIButton,
                    let url = (view.annotation as? GpsData.MyEndPt)?.thumbnailUrl
                 {
                     print("URL: (url)")
                     do{
                         let imageData: Data = try Data(contentsOf: url as URL)
                         let image = UIImage(data: imageData)
                         thumbnailImageButton.setImage(image, for: UIControl.State.normal)
    
                     }catch{
                         print("Unable to load image data: (error)")
                     }
                 }
             }
         }
    
    
     }
    
    }
    
    }
    

Debug:

 coordinator called
 addEndPoints called

 updateUIView called
 mapview delegate called

 subtitleView: Optional("0 rnLevel 2: 208-240V")
 subtitleView: Optional("1 rnNo EV chargers")
 subtitleView: Optional("2 rnLevel 1: 120 V")
 mapview delegate called

 subtitleView: Optional("0 rnLevel 2: 208-240V")
 subtitleView: Optional("1 rnNo EV chargers")
 subtitleView: Optional("2 rnLevel 1: 120 V")
 mapview delegate called

 subtitleView: Optional("0 rnLevel 2: 208-240V")
 subtitleView: Optional("1 rnNo EV chargers")
 subtitleView: Optional("2 rnLevel 1: 120 V")

<0x10703ea10> Gesture: System gesture gate timed out.
 Missing MeshRenderables for ground mesh layer for (6/6) of ground tiles.  Tile debug info: (Key: 0.2.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 1, PendingMaterial count: 1, Invisible MeshInstances count: 0 | Key: 0.0.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 1, PendingMaterial count: 1, Invisible MeshInstances count: 0 | Key: 1.2.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 2, PendingMaterial count: 2, Invisible MeshInstances count: 0 | Key: 1.1.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 2, PendingMaterial count: 2, Invisible MeshInstances count: 0 | Key: 1.0.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 2, PendingMaterial count: 2, Invisible MeshInstances count: 0 | Key: 0.1.2.255 t:33 kt:0, Has mesh errors: 0, MeshInstance count: 2, PendingMaterial count: 2, Invisible MeshInstances count: 0)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật