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代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- Java里面获取当前服务器的IP地址
public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost();//获取 ...
- unity自带寻路Navmesh入门教程(一)
说明:从今天开始,我阿赵打算写一些简单的教程,方便自己日后回顾,或者方便刚入门的朋友学习.水平有限请勿见怪.不过请尊重码字截图录屏的劳动,如需转载请先告诉我.谢谢! unity自从3.5版本之后,增加 ...
- java aes_cbc_256 加密解密
在之前我们在openssl上和ios上分别测试了 AES256位cbc模式的加密和解密 今天用java提供的api来测试一下:进而确定一下在PC,iOS,安卓上三个平台下的加密解密数据: 1. 首先通 ...
- RedHat下Bugzilla的安装和配置
Bugzilla 是一个开源的缺陷跟踪系统(Bug-Tracking System). OS:RedHat Linux 软件类型:开源 架构:B/S server端模块开发语言:perl(c/c++) ...
- ubuntu的一些常用命令,测试版本:Ubuntu 12.04.5 LTS
最近配置了一台Linux服务器,选用的是Ubuntu 12.04.5 LTS版本. 把之前放在Windows Server 2003上的网站移到了现在的服务器上,给我的感受用一个字形容:真JB快! 网 ...
- DEVExpress GridControl|TableView |FormatConditions 按一定格式设置相应内容
Get到一个新技能,感觉好棒.摘自DEV官网:https://www.devexpress.com/Support/Center/Example/Details/T135593 <Window ...
- MySQL使用技巧收集,持续更新中......
1.查询时按某一内容为中文的字段,以拼音字母排序: SELECT * FROM game ORDER BY CONVERT(name USING GBK);
- 查看APK中MD5签名的方法
(需下载jdk) 1. 先将apk文件重命名为zip文件 2. 解压zip,其中的META-INF/CERT.RSA文件即MD5签名文件 3. cmd下打开黑窗口,敲入如下命令: keytool -p ...
- 学习iOS【3】数组、词典和集合
一.数组 1.不可变数组NSArray arrayWithObjects:使用一组对象作为元素创建不可变数组,注意数组的最后一个值需要指定为nil,用来表示参数的结束,但是nil并不会存储在数组中. ...
- 三:关于tcp
转自:http://www.jellythink.com/archives/705 TCP是什么? 具体的关于TCP是什么,我不打算详细的说了:当你看到这篇文章时,我想你也知道TCP的概念了,想要更深 ...