パスを描画しようとしています ( でMKMapView
)。しかし、私は持っています:
NSInvalidArgumentException '、理由:' *** - [NSMutableOrderedSet addObject:]: オブジェクトを nil にすることはできません '。
NSTimer
関数を呼び出すこのボタンアクションがありますstop
@IBAction func startRoute(sender: UIButton) {
// Timer stop() function
// Each 4 seconds
timer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: #selector(ViewController.stop), userInfo: nil, repeats: true)
}
そして、これは私のstop()
関数で、「開始点」を配置し、現在の場所をpoints
タイプの呼び出されたベクトルに追加var points: [CLLocationCoordinate2D] = []
し、addOverlay でパスを描画します。
func stop() {
if (self.initialFlag == 0) {
// Put flag to 1
self.initialFlag = 1
// Add a Annotation
let sourceAnnotation = MKPointAnnotation()
sourceAnnotation.title = "Start Point"
sourceAnnotation.coordinate = (self.locationManager.location?.coordinate)!
self.mapView.showAnnotations([sourceAnnotation], animated: true)
}
// Get current point location
let currentLocation = CLLocationCoordinate2DMake((self.locationManager.location?.coordinate.latitude)!,(self.locationManager.location?.coordinate.longitude)!);
// We add points every 4 seconds then draw the map points
self.points.append(currentLocation)
// Draw the path
geodesic = MKGeodesicPolyline(coordinates: &points[0], count: points.count)
// And I have the error in this line below.
self.mapView.addOverlay(self.geodesic, level: .AboveRoads)
}