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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -