swift - how to wait for requestLocation before proceeding? -
i'm requesting user location when button pressed triggers api call. don't want make api call before latitude/longitude values obtained requestlocation()
call. thought poll while loop checking if optional variables latitude == nil || longitude == nil
, sits in while loop forever. need have kind of waiting values because if don't send nils api call, since takes few seconds location. make sure api request isn't called until latitude/longitude values set requestlocation()
call?
call api delegate method of cllocationmanagerdelegate
func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) { locationmanager.stopupdatinglocation() let location = locations.last! cllocation latittude = string(format: "%f", location.coordinate.latitude) longitude = string(format: "%f", location.coordinate.longitude) // call api here }
hope you.
thanks
Comments
Post a Comment