ios - Update location when user allows location tracking -


i'm trying animate user when accepts location tracking. code works when have accepted location tracking , loads view have view reload when press accept on location tracking.

override func viewdidload() {     super.viewdidload()       //prepare user      if cllocationmanager.authorizationstatus() != .authorizedalways {          // may need change support location based notifications         locationmanager.requestalwaysauthorization()         print("hello")          mapview.setvisiblemaprect(mapview.visiblemaprect, animated: true)      }else {         locationmanager.startupdatinglocation()      }     locationmanager.delegate = self     locationmanager.desiredaccuracy = kcllocationaccuracybest      mapview.delegate = self  } 

animated user location code

//get user location func locationmanager(_ manager: cllocationmanager, didupdatelocations locations: [cllocation]) {     //show map @ users current location     let location = locations[0]     let span:mkcoordinatespan = mkcoordinatespanmake(0.02,0.02 )     let mylocation:cllocationcoordinate2d = cllocationcoordinate2dmake(location.coordinate.latitude, location.coordinate.longitude)     let region:mkcoordinateregion = mkcoordinateregionmake(mylocation, span)     mapview.setregion(region, animated: true)     self.mapview.showsuserlocation = true      locationmanager.stopupdatinglocation()    } 

you can use:

func locationmanager(_ manager: cllocationmanager, didchangeauthorization status: clauthorizationstatus) {     switch status {     case .notdetermined:         locationmanager.requestalwaysauthorization()         break     case .authorizedwheninuse:         locationmanager.startupdatinglocation()         break     case .authorizedalways:         locationmanager.startupdatinglocation()         break     default:         break     } } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -