firebase - Swift - How to get latitude and longitude value outside function LocationManager() -


i working firebase db, , want save lat,long value of device on firebase. had 2 value locationmanager()

this function locationmanager()

func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) {        let lastlocation: cllocation = locations[locations.count - 1]        let lat = string(format: "%.6f", lastlocation.coordinate.latitude)        let long = string(format: "%.6f", lastlocation.coordinate.longitude)     } 

next, try save lat,long on firebase:

 ref = firdatabase.database().reference()     ref.setvalue(lat) 

error: "use of unresolved identifier".

how latitude , longitude value outside function locationmanager().

you can declare cllocationmanagerdelegate right of class definition.

class yourclass {     private var currentcoordinate: cllocationcoordinate2d? } 

and in location delegate method assign current value

func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!) {     currentcoordinate = manager.location.coordinate }   

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -