微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决即使在 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 举报,一经查实,本站将立刻删除。