SwiftでDelegate設定時に「Class "ViewController" has no initializers"のエラーが出てしまいます。
現在実装しているのはGoogle Mapによる任意の場所の地図表示と現在地の地図表示です。
現在地の地図表示を実装する際にCLLocationManagerDelegateのDelegateを設定したのですが、その際にこのエラーが出ました。
この実装に必要なCoreLocation.frameworkは追加・importしてあります。
どのようにすれば解決するでしょうか?
よろしくお願いいたします。
コードはこちらになります(実装途中です)
swift
1import UIKit 2import CoreLocation 3 4import GoogleMaps 5 6// ここでエラー 7class ViewController: UIViewController, CLLocationManagerDelegate { 8 9 // 現在地の位置情報の取得にはCLLocationManagerを使用 10 var myLocationManager: CLLocationManager! 11 // 取得した緯度を保持するインスタンス 12 var latitude: CLLocationDegrees! 13 // 取得した経度を保持するインスタンス 14 var longitude: CLLocationDegrees! 15 16 var lonLabel: UILabel 17 var latLabel: UILabel 18 19 override func viewDidLoad() { 20 super.viewDidLoad() 21 // Do any additional setup after loading the view, typically from a nib. 22 23 let camera = GMSCameraPosition.camera(withLatitude: -33.86,longitude: 151.20, zoom: 6) 24 let mapView = GMSMapView.map(withFrame: CGRect(x:0, y:50, width:320, height:220), camera: camera) 25 self.view.addSubview(mapView); 26 27 let marker = GMSMarker() 28 marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) 29 marker.title = "Sydney" 30 marker.snippet = "Australia" 31 marker.map = mapView 32 33 let nowcamera = GMSCameraPosition.camera(withLatitude: longitude,longitude: latitude, zoom: 6) 34 // let rect = CGRect(x: 100, y:50, width: 100, height: 100) 35 let nowmapView = GMSMapView.map(withFrame: CGRect(x:0, y:350, width:320, height:220), camera: nowcamera) 36 // mapView.isMyLocationEnabled = true 37 self.view.addSubview(nowmapView); 38 39 let nowmarker = GMSMarker() 40 nowmarker.position = CLLocationCoordinate2DMake(-33.86, 151.20) 41 nowmarker.title = "current location" 42 nowmarker.snippet = "now" 43 nowmarker.map = mapView 44 45 // 現在地を取得します 46 myLocationManager = CLLocationManager() 47 myLocationManager.delegate = self 48 myLocationManager.desiredAccuracy = kCLLocationAccuracyBest 49 myLocationManager.distanceFilter = 100 50 myLocationManager.startUpdatingLocation() 51 52 } 53 54 55 func getnowlocation() { 56 //現在地取得 57 myLocationManager.startUpdatingLocation() 58 } 59 60 private func locationManager(manager: CLLocationManager!,didUpdateLocations locations: [AnyObject]!){ 61 print("緯度:\(manager.location?.coordinate.latitude)") 62 print("経度:\(manager.location?.coordinate.longitude)") 63 } 64 65 /** 位置情報取得失敗時 */ 66 func locationManager(manager: CLLocationManager!, didFailWithError error: Error!) { 67 NSLog("Error") 68 } 69 70 override func didReceiveMemoryWarning() { 71 super.didReceiveMemoryWarning() 72 // Dispose of any resources that can be recreated. 73 } 74 75 76} 77 78
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。