首先,定义和继承协议CLLocationManagerDelegate
var locManager:CLLocationManager?;
self.locManager = CLLocationManager();//[[CLLocationManager alloc] init];
self.locManager!.delegate = self;
self.locManager!.desiredAccuracy = kCLLocationAccuracyBest;
self.locManager!.distanceFilter = 5.0;
//设置定位权限 仅ios8有意义
self.locManager?.requestWhenInUseAuthorization();//前台定位
self.locManager?.startUpdatingLocation();
func locationManager(manager: CLLocationManager!,dIDUpdatetoLocation newLocation: CLLocation!,fromLocation oldLocation: CLLocation!) {
println("经度:%g",newLocation.coordinate.latitude);
println("纬度:%g",newLocation.coordinate.longitude);
}
func locationManager(manager: CLLocationManager!,dIDFailWithError error: NSError!) {
println("locationManager error");
}
还有一点,别忘了在info.pList里,加一项:
NSLocationWhenInUseUsageDescription,设为YES
总结以上是内存溢出为你收集整理的Swift开发教程--如何通过定位来获取经纬度全部内容,希望文章能够帮你解决Swift开发教程--如何通过定位来获取经纬度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)