如何使用照片位置数据

时间:2015-08-06 08:05:09

标签: ios iphone swift geolocation

当我拍照时我想保存位置(纬度,经度)。我应该在调用locationManager startUpdatingLocation时使用UIImagePickerController, didFinishPickingMediaWithInfo,还是通过其他方式从照片中获取位置数据

2 个答案:

答案 0 :(得分:1)

你可以这样做

import CoreLocation

将CLLocationManagerDelegate添加到View控制器类声明标题

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


        locationManager.requestAlwaysAuthorization()
    }


        locationManager.startUpdatingLocation()

该代表将要求进行位置更改

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

此代表将调用位置管理器中的问题

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

    }

希望它有所帮助。

答案 1 :(得分:0)

最快的方法是使用

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

    locationManager.startUpdatingLocation()
}

从那里得到lat和long