How to show all map pins in mapView even when zoomed out in Swift iOS

Viewed 148

I have many pins added to my mapView, but when the map is zoomed out or even closely zoomed in, not all the pins show, unless you zoom in deeply.

How do I make it such that all the pins are shown in a specified zoomed-out level?

side note: I specified the color of the pins to be orange, but after a while, they turn back to red why is that?

here is my code:

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
       }
0 Answers
Related