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代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- iOS runtime 初步学习
注: 在Xocde5之后, 使用运行时方法需要进行2步设置1. 在Build Setting中搜索'msg', 设置'Strict Checking' 为 NO2. 使用需要导入头文件 #import ...
- hdu4273Rescue(三维凸包重心)
链接 模板题已不叫题.. 三维凸包+凸包重心+点到平面距离(体积/点积) 体积-->混合积(先点乘再叉乘) #include <iostream> #include<cstd ...
- hdu4449Building Design(三维凸包+平面旋转)
链接 看了几小时也没看懂代码表示的何意..无奈下来问问考研舍友. 还是考研舍友比较靠谱,分分钟解决了我的疑问. 可能三维的东西在纸面上真的不好表示,网上没有形象的题解,只有简单"明了&quo ...
- webpack 学习笔记
1.html-webpack-plugin 该插件主要作用是在release时,自动向index.html 文件中写入 <script>xx/xx/bundle.js</script ...
- Hangfire项目使用
基本介绍: hangfire 主要用于根据设置时间来执行任务,间隔几分钟执行一次,每天几点钟执行一次,如此执行任务. 方法: backgroundjob.enqueue(()=>"要执 ...
- 谈谈javascript中的日期Date对象
一.日期对象 在javascript中并没有日期型的数据类型,但是提供了一个日期对象可以操作日期和时间. 日期对象的创建: new Date();二.将日期对象转换为字符串 将日期对象转换为字 ...
- Load Runner录制C/S客户端
1. 打开应用程序 2. 点击如下菜单 弹出窗口如下 3. 点击New,弹出窗口如下,选择Web(HTTP/HTML) 4. 点击Create,弹出窗口 5. 点击OK, ...
- 为了防止采集,把文章中出现的URL链接随机大小写(PHP实现)
<?php $string = "http://www.kxblogs.com/n/20161115/74439155.html"; $string = explode('/ ...
- The ProgID of the WorkspaceName's workspace factory
The ProgID of the WorkspaceName's workspace factory [C#]public stringWorkspaceFactoryProgID {get; se ...
- Oracle管理口令遗忘解决办法
刚装Oracle11g后忘记了安装时设置的管理口令,可以通过如下方法重置指定用户名密码: 1.打开sql plus,在“请输入用户名”提示符后输入“/as sysdba”,链接数据库后通过“alter ...