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
Post a Comment