首页 > 其他 > 详细

CoreLocation简单应用

时间:2014-09-30 22:15:00      阅读:231      评论:0      收藏:0      [点我收藏+]

1、获取locationManager

let locationManager: CLLocationManager = CLLocationManager()

2、设置locationManager的精度

locationManager.desiredAccuracy = kCLLocationAccuracyBest

3、如果是ios8需要

locationManager.requestAlwaysAuthorization()

4、开始监听数据的更新

locationManager.startUpdatingLocation()

5、添加locationManagerDelegate的回调函数,并将经纬度打出

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){

        var location:CLLocation = locations[locations.count - 1] as CLLocation

        if(location.horizontalAccuracy > 0){

            println("\(location.coordinate.latitude)")

            println("\(location.coordinate.longitude)")

                       

        }

6、设置locationManager的代理

locationManager.delegate = self

7、locationManager错误处理

func locationManager(manager: CLLocationManager!, rangingBeaconsDidFailForRegion region: CLBeaconRegion!, withError error: NSError!){

            println(error)

    }

8、关闭数据更新

locationManager.stopUpdatingLocation()

        

    }

CoreLocation简单应用

原文:http://www.cnblogs.com/scaptain/p/4002659.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!