MapKit in iOS 8 and Swift -


i'm trying use mapkit on ios 8 , keep getting error:

trying start mapkit location updates without prompting location authorization. must call    -[cllocationmanager requestwheninuseauthorization] or -[cllocationmanager  requestalwaysauthorization] first.  

looking here, found had implement nslocationwheninusagedescription in plist , make call locationmanager.requestwheninuseauthorization() nothing happens , still error in console. doing wrong?

in application delegate made optional var locationmanager outside class , set

locmanager = cllocationmanager() locmanager!.requestwheninuseauthorization() 

this causes alert view pop nslocationwheninuseusagedescription or nslocationalwaysusagedescription if change appropriately.

then in view controller file made var outside class hold local cllocationmanager. set

if locmanager {         locman = locmanager!         locman!.delegate = self     } 

then can use delegate method

func locationmanager(_manager: cllocationmanager!,didchangeauthorizationstatus status: clauthorizationstatus) 

which gets called when authorisation status changes, when user responds pop up. inside can use bit of code put user location on map

if status == clauthorizationstatus.authorizedwheninuse {         map.showsuserlocation = true     } 

will add users location map if authorised when in use.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -