0

So actually there was a similar question to mine and I found it here How to get iPhone Maps app blue dot with light blue field for current location? , I tried this solution but it didn't work, that's why it's time for my next question...

I have a map view in my ios swift app and I'm centering it on user's location. So far it works great but the location is marked with a red pin, and instead of that I want I want this typical apple blue dot with a field around it. My code is as follows:

override func viewDidAppear(animated: Bool) {

    super.viewDidAppear(animated)
    mapView.delegate = self

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(appDelegate.getLocation().coordinate, 500, 500)

    mapView.setRegion(coordinateRegion, animated: true)
    mapView.showsUserLocation = true

    print("MapEvents: \(appDelegate.getLatitude()), \(appDelegate.getLongitude())") 
    //this prints correct GPS coords

}

so what am I doing wrong?

==== EDIT

Following Ahmed's clue in the comment section - yes, I have this method implemented:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
        var reuseId = ""
        if annotation.isKindOfClass(FBAnnotationCluster) {
            reuseId = "Cluster"
            var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
            clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
            return clusterView
        } else {
            reuseId = "Pin"
            var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
            pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
            pinView!.calloutOffset = CGPoint(x: -5, y: 5)
            pinView!.canShowCallout = true
            pinView!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView

            return pinView

        }


    }

The reason for that is because I'm using marker clustering from this tutorial https://github.com/ribl/FBAnnotationClusteringSwift

when I commented out this method I see the blue dot, which is great, but now I need to bring the old code back - is there a way that I could use both functionalities (clustering and blue dot)? How should I modify my view for annotation method then?

Thanks a lot!

Community
  • 1
  • 1
user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

1

In the MKMapView viewForAnnotation delegate method, return nil if the annotation's type is MKUserLocation.

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation { return nil }
    var reuseId = ""
    if annotation.isKindOfClass(FBAnnotationCluster) {
        reuseId = "Cluster"
        var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
        clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
        return clusterView
    } else {
        reuseId = "Pin"
        var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView!.calloutOffset = CGPoint(x: -5, y: 5)
        pinView!.canShowCallout = true
        pinView!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView

        return pinView

    }


}
Ahmed Onawale
  • 3,992
  • 1
  • 17
  • 21