swift 定位



- import UIKit
- import CoreLocation //系统定位包
- class ViewController: UIViewController,CLLocationManagerDelegate {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- getCurrentLocation()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- //CodeStart
- /// 定位对象
- let locationManager = CLLocationManager()
- /// 当前所在城市(默认空)
- var currentCity = ""
- /**
- 定位获取所在城市
- */
- func getCurrentLocation(){
- locationManager.desiredAccuracy = kCLLocationAccuracyBest
- locationManager.delegate = self
- if(UIDevice.currentDevice().systemVersion>="8.0"){
- //locationManager.requestAlwaysAuthorization()
- locationManager.requestWhenInUseAuthorization()
- }
- locationManager.startUpdatingLocation()
- }
- /**
- 定位失败
- */
- func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
- println(error.code)
- }
- /**
- 定位完成调用
- */
- func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
- let cloc = locations.last as! CLLocation
- let geoCoder = CLGeocoder()
- var error = NSError()
- geoCoder.reverseGeocodeLocation(cloc, completionHandler: { (placeMarks:[AnyObject]!, error:NSError!) -> Void in
- if error == nil {
- var placeMark: AnyObject = placeMarks[0]
- var locationInfo:Dictionary = placeMark.addressDictionary
- var locationCity = locationInfo["State"] as! String
- if self.currentCity != locationCity{
- self.currentCity = locationCity
- println("当前定位城市:\(self.currentCity)")
- }
- }
- })
- manager.stopUpdatingLocation()
- }
- }
swift 定位的更多相关文章
- swift 定位 根据定位到的经纬度转换城市名
好久没写随笔了 最近这段时间项目有点紧 天天在加班 国庆 一天假都没放 我滴娃娃 好啦 牢骚就不发了 毕竟没有什么毛用 待我那天闲了专门写一篇吐槽的随笔
- 使用CoreLocation进行定位(Swift版)
在应用开发中,很多情况需要我们获取到当前的位置和高度信息,方便搜索周边,查看周边相同应用等,一切与定位有关的都得使用CoreLocation库,而且,系统是不允许第三发定位的,当然可以使用第三方对其封 ...
- Swift基础--定位
// // ViewController.swift // JieCoreLocation // // Created by jiezhang on 14-10-4. // Copyright (c) ...
- Swift - 使用CoreLocation实现定位(经纬度、海拔、速度、距离等)
CoreLocation是iOS中一个提供设备定位的框架.通过这个框架可以实现定位处理,从而获取位置数据,比如经度.纬度.海拔信息等. 1,定位精度的设置 定位服务管理类CLLocationMan ...
- Swift - 给表格UITableView添加索引功能(快速定位)
像iOS中的通讯录,通过点击联系人表格右侧的字母索引,我们可以快速定位到以该字母为首字母的联系人分组. 要实现索引,我们只需要两步操作: (1)实现索引数据源代理方法 (2)响应点击索引触发的代理 ...
- 基于swift MKMapkit 开发的地图定位导航
// DTOneViewController.swift // Mapper-JSON // // Created by kcl on 16/8/8. // Copyright © 2016年 ...
- swift 相机、相册、定位的权限判断
//是否开启相机权限 func IsOpenCamera() -> Bool{ let authStatus = AVCaptureDevice.authorizationStatus(for: ...
- 定位框一闪而过 iOS Swift
需求:获取经纬度. 方案:我自定义了一个类模块CLLocationModule.swift 备注以下代码里 let IS_IOS8 = (UIDevice.currentDevice().system ...
- 使用Xcode HeaderDoc和Doxygen文档化你的Objective-C和Swift代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- javascript中利用柯里化函数实现bind方法
柯理化函数思想:一个js预先处理的思想:利用函数执行可以形成一个不销毁的作用域的原理,把需要预先处理的内容都储存在这个不销毁的作用域中,并且返回一个小函数,以后我们执行的都是小函数,在小函数中把之前预 ...
- Nodejs报错集
1.ReferenceError: userModule is not defined A:1>检查app.js文件中是否调用userModule所在的文件(const userModule=r ...
- WinForm中MouseEnter和MouseLeave混乱的问题
MouseEnter+MouseLeave不行,我用了MouseMove+MouseLeave,效果一样 最近做个聊天的系统,仿照qq的界面设计,像qq聊天界面中字体.表情.截图等图片,鼠标放上去显示 ...
- PHP简单文件上传
一个简单的PHP上传文件的例子: upload.html <html> <body> <form action="upload.php" method ...
- 【图像】Matlab图像标定工具箱
参考教程: Matlab工具箱教程 http://www.vision.caltech.edu/bouguetj/calib_doc/ 摄像机模型 http://oliver.zheng.blog ...
- 【A Global Line Matching Algorithm for 2D Laser Scan Matching in Regular Environment】
只看了前面的部分,灭有看实验,觉得整体风格比较傻白甜,与我的想法不谋而合.简单明了,用起来应该比较方便. 初步探测:如果有直线,就给线性插值一下. 分级聚类:利用简单的阈值给聚类了一下,分成了段段. ...
- C++输入cout与输出cin
输入和输出并不是C++语言中的正式组成成分.C和C++本身都没有为输入和输出提供专门的语句结构.输入输出不是由C++本身定义的,而是在编译系统提供的I/O库中定义的.C++的输出和输入是用" ...
- Oracle 表连接
Oracle 表之间的连接分为三种: 1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不 ...
- css划隔横线的两种方法
css划隔横线的两种方法 方法一:用DIV,代码如下:(推荐此方法) <div style="width:800px;height:1px;margin:0px auto;pa ...
- 开源代码Window下搭建rtmp流媒体服务器
合肥程序员群:49313181. 合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入) Q Q:408365330 E-Mail:egojit@qq.com 综合:有这样需求,将摄像头 ...