zoukankan      html  css  js  c++  java
  • CoreLocation简单应用

    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()

            

        }

  • 相关阅读:
    BZOJ 2752: [HAOI2012]高速公路(road)
    codevs 1979 第K个数
    洛谷 P2680 运输计划
    hdu 3501 Calculation 2
    POJ 2417 Discrete Logging
    比较数组和字典
    js事件之event.preventDefault()与event.stopPropagation()用法区别
    alert
    js基本类型的包装对象
    js取自定义data属性
  • 原文地址:https://www.cnblogs.com/scaptain/p/4002659.html
Copyright © 2011-2022 走看看