SHARE
TWEET

Untitled

a guest Oct 5th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import WatchKit
  2. import Foundation
  3. import CoreLocation
  4.  
  5. class LocationOutside{
  6.    
  7.     var locationManager: CLLocationManager = CLLocationManager()
  8.    
  9.    init(){
  10.         locationManager.requestWhenInUseAuthorization()
  11.         locationManager.desiredAccuracy =  kCLLocationAccuracyHundredMeters
  12.         locationManager.delegate = (self as! CLLocationManagerDelegate)
  13.         locationManager.requestLocation()
  14.     }
  15.    
  16.     func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  17.         let currentLoc =  locations[0]
  18.         let lat = currentLoc.coordinate.latitude
  19.         let long = currentLoc.coordinate.longitude
  20.         print(lat)
  21.         print(long)
  22.  
  23.     }
  24.    
  25.     func locationManager(_manager: CLLocationManager,didFailWithError error: Error){
  26.         if let locationErr = error as? CLError{
  27.             switch locationErr{
  28.             case CLError.locationUnknown:
  29.                 print("unknown location")
  30.             case CLError.denied:
  31.                 print("denied")
  32.             default:
  33.                 print("another type of location error")
  34.             }
  35.         }else{
  36.                 print("other error: ", error.localizedDescription)
  37.             }
  38.         }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top