即使在 Swift iOS 中缩小,如何在 mapView 中显示所有地图图钉

问题描述

我在我的 mapView 中添加了许多图钉,但是当地图缩小甚至放大时,并非所有图钉都显示出来,除非您放大得很深。

如何使所有图钉都以指定的缩小级别显示

附注:我将引脚的颜色指定为橙色,但过了一会儿,它们又变回红色,这是为什么?

这是我的代码

func shopsLocations(){
        
       
        db.collection("Shops").getDocuments() { (querySnapshot,err) in
            if err != nil {
            } else {
                for document in querySnapshot!.documents {
              
                    let lat = document["latitude"] as? String
                    let long = document["longitude"] as? String
                    self.detailsKey = document["shopPID"] as? String
                    let myFloat = (lat! as Nsstring).doubleValue
                    let myFloat2 = (long! as Nsstring).doubleValue
                    let annotation = MyAnnotation(shopPID: document["shopPID"] as! String,coordinate:CLLocationCoordinate2D(latitude: myFloat,longitude: myFloat2),title:(document["name"] as? String)!,subtitle: "Click to view shop details" )
            
                    
                    self.mapView.addAnnotation(annotation)
                }
            }
        }
    }
    
    func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
           if annotation is MKUserLocation {
               return nil
           }
            
           let reuseId = "pin"
           var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKMarkerAnnotationView
        
           if pinView == nil {
            
            pinView = MKMarkerAnnotationView(annotation: annotation,reuseIdentifier: reuseId)
            pinView?.canShowCallout = true
            pinView?.isDraggable = false
            pinView?.markerTintColor = UIColor.orange
            pinView?.animatesWhenAdded = true
         
            let rightButton: AnyObject! = UIButton(type: UIButton.ButtonType.detaildisclosure)
            pinView?.rightCalloutAccessoryView = rightButton as? UIView
            
           }
           else {
               pinView?.annotation = annotation
            
           }
           return pinView
       }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)