博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift基础--定位
阅读量:7158 次
发布时间:2019-06-29

本文共 2194 字,大约阅读时间需要 7 分钟。

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

你可能感兴趣的文章
Mybatis <if test> 判断数字时的问题
查看>>
Log(jcl&slf4j)
查看>>
Scrum中,拆分故事的INVEST原则
查看>>
mybatis-dynamic sql
查看>>
runtime 动态增加属性
查看>>
select实现精确定时器
查看>>
Centos下安装类百度文库环境
查看>>
JS监听对象属性读写的5种方法
查看>>
多个wifi路由器组建一个wifi网络增加网络覆盖范围
查看>>
作为“创业导师”的天使投资人
查看>>
改变世界梦想的创业者
查看>>
国产数据库一览表
查看>>
获取url的参数包括中文参数
查看>>
ios 中使用 block
查看>>
详解Google Authenticator工作原理
查看>>
树莓派设置屏幕待机时间
查看>>
mysql问题汇总
查看>>
php/Java Web国际化的联合解决方案
查看>>
AndroidStudio环境的搭建
查看>>
Postgresql数据类型
查看>>