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

最新文章

  1. 窥探Vue.js 2.0 - Virtual DOM到底是个什么鬼?
  2. ASP.NET Core 中文文档 第四章 MVC(3.9)视图组件
  3. demo02TextView
  4. Java基础:三步学会Java Socket编程
  5. c++相关知识回顾
  6. linux 进程间信号量管理程序之sem_timedwait使用
  7. Docker for windows10 配置镜像加速
  8. Vue内容分发slot
  9. Hibernate学习---Configuration,Session,SessionFactory
  10. MTCNN算法与代码理解—人脸检测和人脸对齐联合学习
  11. Python——Menu控件
  12. poj3321 dfs序+树状数组单点更新 好题!
  13. (实用)Ubuntu 开启NFS服务
  14. miRTarBase 数据库简介
  15. 2018/03/23 每日一个Linux命令 之 sed
  16. Linux——shell简单学习(二)
  17. SpringBoot 使用小技巧合集
  18. ubuntu 忘记root密码了不用怕,看这里
  19. docker容器修改hosts文件,重启失效问题解决
  20. C++的字符串分割函数

热门文章

  1. NOIP2012 同余方程 题解
  2. 2015.03.16,外语,读书笔记-《Word Power Made Easy》 00 “如何最大限度的利用本书”学习笔记
  3. 转:utf8汉字编码16进制对照
  4. 【POJ 2481】 Cows
  5. Django迁移到mysql数据库时的错误
  6. 服务器未能识别http头soapaction的值
  7. c#常量如何使用
  8. 前端学习笔记-CSS
  9. SpringBoot(八) Spring和消息队列RabbitMQ
  10. LeetCode(17)Letter Combinations of a Phone Number