Yesterday I asked a question here in stack Overflow about how to embed my current location in message body
I had got an answer and I corrected my code
My code works just fine in console, but i couldn't figure out how to get the data from displayLocationInfo function and store them in variables; then put variables in message body.
I'm sorta new in iPhone development
Any help ?
class Location: NSObject,CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var currentLocation : CLPlacemark?
var detectLocation : CLLocationManager?
var locManager = CLLocationManager()
func viewDidLoad()
{
viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
func updateLocation()
{
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationManager.stopUpdatingLocation()
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)->Void in
if (error != nil)
{
print("Error: " + error!.localizedDescription)
return
}
if placemarks!.count > 0
{
let pm = placemarks![0]
self.displayLocationInfo(pm)
}
else
{
print("Error with the data.")
}
})
}
func displayLocationInfo(placemark: CLPlacemark)
{
self.locationManager.stopUpdatingLocation()
print(placemark.locality)
print(placemark.postalCode)
print(placemark.administrativeArea)
print(placemark.country)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Error: " + error.localizedDescription)
}
}