swift mapkit 增加 overlay 不进回调的问题
import UIKit 
import MapKit 

class ViewController: UIViewController, MKMapViewDelegate { 

    var points:NSMutableArray? 
    let locationManager = CLLocationManager() 
    //var currentLocation: CLLocationCoordinate2D? 
    var routeLine: MKPolyline? 

    @IBOutlet weak var mapView: MKMapView! 
    //@IBOutlet weak var currentLocationButton: UIButton! 


    override func viewDidLoad() { 
        super.viewDidLoad() 
        // Do any additional setup after loading the view, typically from a nib. 

        if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.NotDetermined { 
            locationManager.requestAlwaysAuthorization() 
        } 

        self.currentLocationButton.addTarget(self, action: Selector("currentLocationButtonAction"), forControlEvents: UIControlEvents.TouchUpInside) 

        self.mapView.mapType = MKMapType.Standard 
        self.mapView.userTrackingMode = MKUserTrackingMode.Follow 
        self.mapView.showsUserLocation = true 
        self.mapView.delegate = self 

        var point = CLLocation(latitude: 121, longitude: 38) 

        if self.points == nil { 
                self.points = NSMutableArray() 
        } 

        self.points?.addObject(point)            

        self.routeLine = self.polyline() 

        if self.routeLine != nil { 
            self.mapView.addOverlay(self.routeLine) 
        } 

    }

    func polyline() -> MKPolyline { 

        var coords = [CLLocationCoordinate2D]() 

        for (var i = 0; i < self.points?.count; i++) { 
            var location = self.points?.objectAtIndex(i) as CLLocation 
            let c = location.coordinate 
            coords.append(c) 

        } 
        return MKPolyline(coordinates: &coords, count: self.points!.count) 
    } 

    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { 
                    println("mark")  //这句并没有打印
        if overlay is MKPolyline { 
            var polylineRenderer = MKPolylineRenderer(polyline: self.routeLine) 
            polylineRenderer.fillColor = UIColor.redColor() 
            polylineRenderer.strokeColor = UIColor.blueColor() 
            polylineRenderer.lineWidth = 4 
            return polylineRenderer 
        } 
        return nil 
    }
}       

1个回答

加上CLLocationManagerDelegate试下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问