ios - how to use my location(latitude,longitude) of CLLocation at viewdidload() -
func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) { let userlocation: cllocation = locations[0] let center = cllocationcoordinate2d(latitude: userlocation.coordinate.latitude, longitude: userlocation.coordinate.longitude) mylat = userlocation.coordinate.latitude mylong = userlocation.coordinate.longitude let region = mkcoordinateregion(center: center, span: mkcoordinatespan(latitudedelta: 0.04, longitudedelta: 0.04)) totalmap.setregion(region, animated: true) } first.. i'm sorry english writning...
i used mylat , mylong in func .. want add user location global variable , use user location in viewdidload..
actually need user location(lat,long) , many other location, , use comparing opration 2 location, , need of location ..
help me
the cllocationmanager works asynchronously. can use in viewdidload() not might think.
you can register callback this:
var onlocationupdate: ((cllocation) -> ())? override func viewdidload() { super.viewdidload() onlocationupdate = { [weak self] location in // location } } and call onlocationupdate?(your_location) in locationmanager(_:didupdatelocations:) method
Comments
Post a Comment