Junwoo Lee
Junwoo Lee

Reputation: 489

locationManager Delegate not working

I have included NSLocationWhenInUsageDescription and NSLocationAlwaysUsageDescription in my info.plst file and my code is like this.

import UIKit
import MapKit



class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate {

@IBOutlet weak var locationSearchBar: UISearchBar!
@IBOutlet weak var mapView: MKMapView!
var selectedLoc: String?
let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.requestAlwaysAuthorization()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    locationManager.startUpdatingLocation()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func locationManager(manager: CLLocationManager, didupdateLocations locations: [CLLocation]) {

}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {

}

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {

}
}

I think I have nothing wrong but it is keep showing this error

Cannot Assign value of type "LocationSelectorViewController" to type "CLLocationManagerDelegate?"

Can you tell me where is the Problem?

Upvotes: 0

Views: 183

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82779

Cannot Assign value of type "LocationSelectorViewController" to type "CLLocationManagerDelegate?"

Ans : Your LocationSelectorViewController class must adopt and conform toCLLocationManagerDelegate protocol.

Add the CLLocationManagerDelegate in your class as shown below.

class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate, CLLocationManagerDelegate {

instead of

 class LocationSelectorViewController: UIViewController, 
UISearchBarDelegate, MKMapViewDelegate {

Upvotes: 1

Related Questions