ios - How to pass latitude and longitude to another function - swift location -
i'm having problem passing latitude , longitude function i'm building api url weather info back. know i'm missing phone call location function before calling weather function. thought location first , store latitude , longitude in variables, , phone call weather function in utilize values.
i've provided comments chain of thought.
any help appreciated. give thanks you.
import uikit import corelocation class viewcontroller: uiviewcontroller, cllocationmanagerdelegate { var locmanager = cllocationmanager() // created these store latitude , longitude, necessary? var lat : double! var long : double! // viewdidload override func viewdidload() { super.viewdidload() // location manager - inquire permission , start updating locmanager.delegate = self locmanager.desiredaccuracy = kcllocationaccuracynearesttenmeters locmanager.requestwheninuseauthorization() locmanager.startupdatinglocation() // need here phone call function lat , long // // weather info using api getcurrentweatherdata() } // latitude , longitude - i'm getting lat , long func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!) { var locvalue : cllocationcoordinate2d = manager.location.coordinate locmanager.stopupdatinglocation() lat = locvalue.latitude long = locvalue.longitude } // i'm using function build api url , weather data. func getcurrentweatherdata() -> void { allow baseurl = nsurl(string: "https://api path here/\(apikey)/") allow forecasturl = nsurl(string: "\(lat),\(long)", relativetourl: baseurl) // more code here // }
instead of storing variables , trying guess when they've been set, should phone call function within locationmanager handler:
func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!) { var locvalue : cllocationcoordinate2d = manager.location.coordinate locmanager.stopupdatinglocation() provideweatherforlocation(locvalue) // or: provideweatherforlocation(latitude: locvalue.latitude, longitude: locvalue.longitude) } ios swift location cllocationmanager
No comments:
Post a Comment