在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
步骤: 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() }
因为领导把我的开发者账号给弄没了,咱没有用真机测试过数据 |
请发表评论