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代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- c/c++中两颗璀璨的明珠
1.指针: 函数指针做函数参数 回调函数 语法现象 意义 实现什么效果 (1).间接赋值成立的三个条件 a.两个变量 b.建立关联 c. *p-> (2).函数指针做函数参数 a.调用的角度去理 ...
- laravel select 传参
传值: $params['select'] = 'taobao_id,title,image,price,coupon_deduct,coupon_condition'; 接受参数 $result = ...
- BZOJ4247挂饰
Description JOI君有N个装在手机上的挂饰,编号为1...N. JOI君可以将其中的一些装在手机上. JOI君的挂饰有一些与众不同--其中的一些挂饰附有可以挂其他挂件的挂钩 ...
- 分布式事务二阶提交DTS系统
前端时间写新交易系统时,经常碰到事务一致性问题,网上搜了一下,有一些解决方法,采用了扫表补偿的方式来完成,刚开始只有几个接口需要处理,工作量还可以,但是后续随着需求的增加,这些场景错综复杂,导致大量时 ...
- ExtJS自制表格Grid分页条
试过Grid自带的load和分页功能,没有成功,干脆就自己写了...... 主要是查询条件比较复杂...... 希望哪位大神能有更好的意见. Ext.define('MyApp.ux.Paginati ...
- Android NDK 项目依赖简单示例
目录文件结构如图, 进入main目录执行命令 .ndkbuild NDK_MODULE_PATH=../ 说明 .ndkbuild请替换成有效的ndk-build的命令 所有文件下载 http://p ...
- 优化Google字体 全面加速WordPress
从5月27号起,由于某些原因,Google服务在大陆的崩溃影响了数百万的站长,因为很多wordpress主题都在使用Google的在线字体方案-google fonts包括新版的WordPress 后 ...
- MySql学习(二) —— where / having / group by / order by / limit 简单查询
注:该MySql系列博客仅为个人学习笔记. 这篇博客主要记录sql的五种子句查询语法! 一个重要的概念:将字段当做变量看,无论是条件,还是函数,或者查出来的字段. select五种子句 where 条 ...
- Transport Block Size, Throughput and Code rate-----http://www.simpletechpost.com/2012/12/transport-block-size-code-rate-protocol.html
Transport Block Size, Throughput and Code rate Since the size of transport block is not fixed, oft ...
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(一)
前言 本系列源自对EF6 CodeFirst的探索,但后来发现在自己项目中构建的时候遇到了一些问题以及一些解决方法,因此想作为一个系列写下来. 本系列并不是教你怎么做架构设计,但可以参照一下里面的方法 ...