ios - myLocationEnabled - Unexpectedly found nil while unwrapping -
i'm trying users location in mapviewcontroller using googlemaps api. i've looked around everywhere , can't figure out why continually getting fatal error: unexpectedly found nil while unwrapping , optional value in particular place.
here code:
class mapviewcontroller: uiviewcontroller { let locationmanager = cllocationmanager() @iboutlet weak var mapview: gmsmapview! override func viewdidload() { super.viewdidload() locationmanager.delegate = self locationmanager.requestwheninuseauthorization() let camera = gmscameraposition.camerawithlatitude(-34.9290, longitude:138.6010, zoom:10) let mapview = gmsmapview.mapwithframe(cgrectzero, camera:camera) mapview.maptype = kgmstypenormal print("calling addmarker") // addmarker() self.view = mapview } extension mapviewcontroller: cllocationmanagerdelegate { func locationmanager(manager: cllocationmanager, didchangeauthorizationstatus status: clauthorizationstatus) { if status == .authorizedwheninuse { locationmanager.startupdatinglocation() mapview.mylocationenabled = true mapview.settings.mylocationbutton = true } } func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) { if let location = locations.first { mapview.camera = gmscameraposition(target: location.coordinate, zoom: 15, bearing: 0, viewingangle: 0) locationmanager.stopupdatinglocation() } } }
this getting error:
i mapview.mylocationenabled
returning nil don't understand why/how.
most mapview nil, not mapview.mylocationenabled. when crash try following lldb command:
po mapview
and tell exactly.
the didchangeauthorizationstatus delegate being called background or before view complete. should move extensions appdelegate.
Comments
Post a Comment