【发布时间】:2016-09-06 08:37:32
【问题描述】:
我正在尝试获取用户位置的经纬度,我已完成以下操作:
导入的核心位置
import CoreLocation
添加核心位置代理
class ViewController: UIViewController, CLLocationManagerDelegate, AVCaptureMetadataOutputObjectsDelegate, DTDeviceDelegate {
定义了这个变量:
var locationManager: CLLocationManager!
然后添加了这个方法:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0]
let long = userLocation.coordinate.longitude;
let lat = userLocation.coordinate.latitude;
print(long, lat)
//Do What ever you want with it
}
但是位置没有被打印出来,我的方法甚至没有得到它。
我将使用核心位置的项目添加到我的 plist 中,并且应用程序在我第一次运行它时要求我使用位置服务。但是现在位置正在打印....我做错了什么?
【问题讨论】:
-
已经在这里回答了:- stackoverflow.com/questions/25296691/…
标签: ios swift core-location