技术文章分类(180)

技术随笔(11)

swift获取经纬度(swift CLLocationManager使用)

步骤:

1,import CoreLocation

2,实现协议:CLLocationManagerDelegate

3,初始化并配置CLLocationManager,实现协议的方法didUpdateLocations

var locationManager:CLLocationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.、
        
        self.reLocationAction(self)

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!){
        let thelocations:NSArray = locations as NSArray
        let location:CLLocation = thelocations.objectAtIndex(0) as CLLocation
        let latitude = location.coordinate.latitude
        let longitude = location.coordinate.longitude
        println(latitude)
        locationManager.stopUpdatingLocation()
    }

    
    
    @IBAction func reLocationAction(sender : AnyObject) {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = 1000.0
        locationManager.startUpdatingLocation()
    }

 

 

因为领导把我的开发者账号给弄没了,咱没有用真机测试过数据

posted @ 2014-06-19 10:42  坤哥MartinLi  阅读(2167)  评论(0编辑  收藏  举报