Swift基础--定位
来源:互联网 发布:中国进出口统计数据库 编辑:程序博客网 时间:2024/05/17 20:51
//// ViewController.swift// JieCoreLocation//// Created by jiezhang on 14-10-4.// Copyright (c) 2014年 jiezhang. All rights reserved.//import UIKitimport CoreLocationclass ViewController: UIViewController, CLLocationManagerDelegate{ required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @IBOutlet weak var longitudeTxt: UITextField! @IBOutlet weak var latitudeTxt: UITextField! @IBOutlet weak var HeightTxt: UITextField! @IBOutlet weak var addressTxt: UILabel! var currLocation : CLLocation! //地址反编译出错误,不清楚什么问题,我是在模拟器上模拟的 @IBAction func reverseGeocode(sender: AnyObject) { var geocoder = CLGeocoder() var p:CLPlacemark? geocoder.reverseGeocodeLocation(currLocation, completionHandler: { (placemarks, error) -> Void in if error != nil { println("reverse geodcode fail: \(error.localizedDescription)") return } let pm = placemarks as [CLPlacemark] if (pm.count > 0){ p = placemarks[0] as? CLPlacemark println(p) }else{ println("No Placemarks!") } }) } //用于定位服务管理类,它能够给我们提供位置信息和高度信息,也可以监控设备进入或离开某个区域,还可以获得设备的运行方向 let locationManager : CLLocationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self //设备使用电池供电时最高的精度 locationManager.desiredAccuracy = kCLLocationAccuracyBest //精确到1000米,距离过滤器,定义了设备移动后获得位置信息的最小距离 locationManager.distanceFilter = kCLLocationAccuracyKilometer } override func viewWillAppear(animated: Bool) { locationManager.startUpdatingLocation() println("定位开始") } override func viewWillDisappear(animated: Bool) { locationManager.stopUpdatingLocation() println("定位结束") } func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){ currLocation = locations.last as CLLocation longitudeTxt.text = "\(currLocation.coordinate.longitude)" latitudeTxt.text = "\(currLocation.coordinate.latitude)" HeightTxt.text = "\(currLocation.altitude)" } func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!){ println(error) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }}
0 0
- Swift基础--定位
- Swift-定位
- Swift学习-基础数据类型
- Swift基础--ijkplayer编译
- swift基础笔记2-闭包
- swift基础笔记3-枚举
- swift基础笔记7-继承
- Swift教程学习笔记-1基础
- swift ios8 定位
- Swift 定位 SwiftLocationManager
- Swift实现手机定位
- Swift基础--解析服务器Json内容
- Swift基础--使用TableViewController自定义列表
- Swift基础--调用第三方OC项目
- Swift基础--使用TableViewController自定义列表
- Swift基础--调用第三方OC项目
- Swift基础--调用第三方OC项目
- Swift教程 swift基础
- QTableWidget使用事项
- Three.js讲解以及WEBGL实例
- C中常见的编程
- 替换系统锁屏遇到的问题
- EntityFramework经典的left join语法
- Swift基础--定位
- Selenium 测试 - 在遇到失败时截图保存
- Effective C++ 读书笔记 条款11:在operator= 中处理"自我赋值"
- 汇编函数的执行过程
- NYOJASCII码排序
- C/C++ 笔试、面试题目大汇总
- 设计模式(二)
- DICOM医学图像处理:浅析SWF、WML、SPS、MPPS
- 在 Oracle Enterprise Linux 和 iSCSI 上构建您自己的 Oracle RAC 11g 集群