2017-09-26 8 views
0

この機能を有効にする方法を見つけ出すことはできません。私は機能を持つアプリを作っています

func RMC(_ manager: CLLocationManager, locations: [CLLocation]) { 
     let manager = CLLocationManager() 
     let location = locations[0] 
     let span:MKCoordinateSpan = MKCoordinateSpanMake(0.001, 0.001) 
     let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude) 
     let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span) 
     let annotation = MKPointAnnotation() 
     annotation.coordinate = location.coordinate 
     mapView.setRegion(region, animated: true) 
     self.mapView.addAnnotation(annotation) 
     annotation.title = "My Car" 

そして、私はこのコードで@IBA機能でそれをアクティブにする:

RMC(CLLocationManager, locations: [CLLocation]) 

それは、このエラーを思い付く:
は予想引数の型を「CLLocationManager.Typeは」「CLLocationManager」

助けてください型の値を変換できません!

答えて

0

CLLocationManagerオブジェクトをインスタンス化して渡す必要があります。今すぐコールサイトで、CLLocationManagerのインスタンスを渡すのではなく、タイプCLLocationManagerを参照しているだけです。 CLLocationsの配列でも同じことをやっていますが、一般的にそれらをインスタンス化するわけではありません。あなたはへの呼び出しを変更する必要があります:それはそれは不可能CLLocationManaterオブジェクトを使用することができますよう、

RMC(CLLocationManager(), locations: []) 

また、あなたが新しいCLLocationManagerを作成し、あなたの関数の最初の行ラインは冗長であり、削除すべきことであるが、 (コンパイラエラーかもしれないが、私は確かめるためにテストしていない)

関連する問題