I have tried this in swift
How to get the current location in watchOS 2?
But It's not working Here is my code in WKInterfaceController
override func awake(withContext context: Any?) {
super.awake(withContext: context)
self.setupLocation()
}
extension InterfaceController: CLLocationManagerDelegate {
func setupLocation() {
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let currentLocation = locations.first else { return }
self.currentLocation = currentLocation
let location = "lat: \(self.currentLocation.coordinate.latitude)\nlong: \(self.currentLocation.coordinate.longitude)"
self.locationLabel.setText(location)
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("LOCATION MANAGER DID FAIL ERROR : \(error)")
}
}
I have added permission in WatchExtension and Main App info.plist as well.
It's still not even asking permission alert. What i'm missing ???? :(