Swift基础--定位
//
// ViewController.swift
// JieCoreLocation
//
// Created by jiezhang on 14-10-4.
// Copyright (c) 2014年 jiezhang. All rights reserved.
// import UIKit
import CoreLocation class 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() } }
Swift基础--定位的更多相关文章
- swift基础:第六部分:类与对象
http://reactnative.cn/docs/0.24/getting-started.html#content(react Native 开发文档) 互联网这个时代,你松懈一天,就会有很多很 ...
- swift基础:第二部分:函数和闭包
今天本来想利用上午的时间本来打算将swift基础部分学习完的,不巧的是,后台来和我讨论用户评价的接口,讨论过后,商讨出一种可行的方案,十几分钟时间过去了,我拿到将接口介入到已经完成的页面中,完美,终于 ...
- Swift基础语法学习总结(转)
Swift基础语法学习总结 1.基础 1.1) swift还是使用// 和/* */ 来注释,并且/* */允许多行注释. 1.2) swift使用print和println打印,它的传参是一个泛型 ...
- Swift基础语法学习总结
Swift基础语法学习总结Swift高级语法学习总结Swift语法总结补充(一) 1.基础 1.1) swift还是使用// 和/* */ 来注释,并且/* */允许多行注释. 1.2) swift ...
- swift -- 基础
swift -- 基础 1.常量和变量 常量: let 变量: var 2.声明常量和变量 常量的声明: let let a = 1 //末尾可以不加分号,等号两边的空格必须对应(同 ...
- iOS Swift 模块练习/swift基础学习
SWIFT项目练习 SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图 +控件 1.UIImag ...
- Swift基础学习
Swift基础学习 http://c.biancheng.net/cpp/html/2242.html 这个网站最近看了一下,对于基本语法解释概括的相对全面,如同重新练习一遍OC似的,挺全面的,谢谢 ...
- UI自动化之8种基础定位
UI自动化的核心在于定位 目录 1.8种基础定位方法 2.xpath定位 3.css定位 4.多组元素 1.8种基础定位方法 driver.find_element_by_id() #id定位 dri ...
- swift基础语法(四) 函数、闭包(Closures)
//函数基本定义 func 函数名(参数名:参数类型=默认值) ->返回值类型{代码块} //无参无返回值函数 func hsmin(){ } //单参无返回值函数 func prin(st:S ...
随机推荐
- HBase使用flush命令之后存储的位置
HBase使用flush命令之后存储的位置 根据系统安装位置的不一样而不一样,当前是在: hadoop fs -ls /apps/hbase/data/data/default/t1 下面: 使用ha ...
- nyoj19(排列组合next_permutation(s.begin(),s.end()))
题目意思: 从n个数中选择m个数,按字典序输出其排列. pid=19">http://acm.nyist.net/JudgeOnline/problem.php?pid=19 例: 输 ...
- 2015.05.11,外语,读书笔记-《Word Power Made Easy》 15 “如何谈论事情进展” SESSION 44
1. not the real McCoy simulate(['simjuleit] v. 假装,冒充,模仿,模拟)来自拉丁simulo,copy的意思.simulo本身派生自拉丁形容词simili ...
- poj2947Widget Factory
对于同余方程的高斯消元啊. 其实也差不多吧.先同一位通分,然后减一下就好了. 主要是判无解和多解的麻烦,需要注意即使有自由元也可能先无解 #include<cstdio> #include ...
- 存储概念解析:NAS与SAN的区别
目前存储网络技术领域中的两个主旋律是SAN(存储区域网络)和NAS(网络连接区域存储),两者都宣称是解决现代企业高容量数据存储需求的最佳选择. 正如在餐厅就餐时大厨不会为您传菜,跑堂不会为您烹制鲜橙烩 ...
- jqueryui slider
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...
- ubuntu 绘制lenet网络结构图遇到的问题汇总
Couldn't import dot_parser, loading of dot files will not be possible的问题 1 .sudo pip uninstall pypar ...
- art-template模板渲染及其过滤器
原生语法 使用原生语法,需要导入template-native.js文件.在HTML中定义模板,注意模板的位置,不要放到被渲染区域,防止模板丢失. <script id="tpl&qu ...
- 用endnote导入bib
首先一般时候需要把IEEE的style包导入. https://endnote.com/downloads/styles/ 具体方法可参考http://muchong.com/html/201006/ ...
- js中,实现对键盘按键的监听:
<script> function keyUp(e) { var currKey=0,e=e||event; currKey=e.keyCode||e.which||e.charCode; ...