BENQ
BENQ

Reputation: 93

How to use a photos location data

WHen I take a photo I want to save the location (Latitude, Longitude). Should I Use the locationManager startUpdatingLocation when UIImagePickerController, didFinishPickingMediaWithInfo is called or is there some other way to get the location data itself from the photo

Upvotes: 1

Views: 52

Answers (2)

chakshu
chakshu

Reputation: 1392

You can do this

import CoreLocation

after it add CLLocationManagerDelegate To your View controller class declaration header

let locationManager = CLLocationManager()
    locationManager.delegate = self
    if CLLocationManager.authorizationStatus() == .NotDetermined
    {


        locationManager.requestAlwaysAuthorization()
    }


        locationManager.startUpdatingLocation()

This delegate will called for location change

 func locationManager(manager: CLLocationManager!,
            didUpdateLocations locations: [AnyObject]!)
        {
      let location = locations.last as CLLocation
      self.locationManager.stopUpdatingLocation()
    }

This delegate will called there is problem in location Manager

 func locationManager(manager: CLLocationManager!,
            didFailWithError error: NSError!)
        {

    }

Hope it helps.

Upvotes: 1

000
000

Reputation: 225

The fastest way will be to use

 func getLocation() {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
    locationManager.requestWhenInUseAuthorization()

    locationManager.startUpdatingLocation()
}

And get the lat and long from there

Upvotes: 0

Related Questions