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代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- OSChina码云试用
首先在码云申请账户. 从 http://git-scm.com/download 下载window版的客户端.下载好,一步一步安装即可. $git config --global user.name ...
- eclipse rcp 打包出适合不同操作系统和操作位数.
http://blog.csdn.net/luoww1/article/details/8677999 http://blog.csdn.net/soszou/article/details/8053 ...
- Android 异步消息处理机制
1.Handler的由来 当程序第一次启动的时候,Android会同时启动一条主线程( Main Thread)来负责处理与UI相关的事件,我们叫做UI线程. Android的UI操作并不是线程安全的 ...
- 从github获取代码
以duilib为例: 1 建立一个文件夹,右键 git bash here. 2 git init 3 git clone https://github.com/duilib/duilib.git
- SSIS数据转换后数值总数差异过大
之前做过一个项目,犯了一个小错误,写出来给大家分享一下,以防大家出同样的错误. 做了一个ETL包,对货品的销售额进行数据转换,字符型 --〉 浮点型: 之后对销售额进行求和,在测试数据结果时发现与销售 ...
- Java 文本文件 读写
Use File/FileInputStream/FileOutputStream. public void testWithFIS() throws IOException{ File file=n ...
- 个人评测——K米
K米APP案例分析 关于 K米 -- 的案例分析 产品 K米的APP (全国KTV点歌,手机直播,互动,交友,预订)的Android客户端 第一部分 调研,评测 评测: 软件的bug,功能评测,黑箱测 ...
- REST架构之Apache Wink
Apache Wink是一个使用简单,稳定的Java框架,用于创建RESTful web services应用程序.Wink包括了一个服务器端模块和一个客户端模块,用于帮助开发者快速高效的开发REST ...
- Excel中提取最大值的问题
在使用excel的时候,碰到了一个如下的问题 意思是以每个字母为条件,取这个字母下面的数字中的最大值,需要注意一个问题是每个字母下面的数字个数不一定相等,例如d下面有四个数字,可以设置如下公式解决: ...
- 关于offsetWidth,offsetHeight,offsetTop,offsetLeft和二维数组的声明
offsetWidth,offsetHeight,offsetTop,offsetLeft 为只读状态,返回的值是int形式 只读形式即不能通过修改其值的大小. 想要修改某元素的这些值的大小(widt ...