30天学习Swift项目实战第五天------获取定位经纬度
2016-08-06 00:00
453 查看
使用CoreLocation来完成定位信息。
本来我还想完成一下经纬度转换为具体地理位置的,但是一直报错,以后补充吧。不想拖进度。
注意,info.plist文件的权限添加。
本项目只有一个类,ViewController:
//
// ViewController.swift
// MyLocation
//
// Created by luopan on 16/8/6.
// Copyright © 2016年 Hust University. All rights reserved.
//
import UIKit
//导入定位框架包
import CoreLocation
class ViewController: UIViewController , CLLocationManagerDelegate{
}
尝试了很多种方法去转换经度度到具体地理信息,但是不成功。时间好玩,明天在搞吧。
本来我还想完成一下经纬度转换为具体地理位置的,但是一直报错,以后补充吧。不想拖进度。
注意,info.plist文件的权限添加。
本项目只有一个类,ViewController:
//
// ViewController.swift
// MyLocation
//
// Created by luopan on 16/8/6.
// Copyright © 2016年 Hust University. All rights reserved.
//
import UIKit
//导入定位框架包
import CoreLocation
class ViewController: UIViewController , CLLocationManagerDelegate{
@IBOutlet weak var showLabel: UILabel! //定位管理器 var locationManager: CLLocationManager! //按钮点击事件 [@IBAction](http://my.oschina.net/u/866341) func GetLocation(sender: UIButton) { locationManager = CLLocationManager() // 设置代理为当前对象 locationManager.delegate = self // 设置定位的精确度 locationManager.desiredAccuracy = kCLLocationAccuracyBest //授权定位 locationManager.requestAlwaysAuthorization() if CLLocationManager.locationServicesEnabled(){ // 开启定位服务 locationManager.startUpdatingLocation() }else{ showLabel.text = "请打开定位服务。" } } //定位失败回掉方法 func locationManager(manager: CLLocationManager, didFailWithError error: NSError) { showLabel.text = error.localizedDescription print(error.localizedDescription) } // 定位更新地理信息调用的代理方法 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if locations.count > 0 { let newLocation = locations.last let longitude = newLocation?.coordinate.longitude let latitude = newLocation?.coordinate.latitude self.showLabel.text = "经度是:\(longitude!)----纬度是:\(latitude!)" } } override func viewDidLoad() { super.viewDidLoad() }
}
尝试了很多种方法去转换经度度到具体地理信息,但是不成功。时间好玩,明天在搞吧。
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程
- 浅析iOS应用开发中线程间的通信与线程安全问题
- iOS中的UIKeyboard键盘视图使用方法小结
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法