博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用AKLocationManager定位
阅读量:7138 次
发布时间:2019-06-28

本文共 1225 字,大约阅读时间需要 4 分钟。

使用AKLocationManager定位

 

以下是使用情况:

是不是很简单呢,我们可以将它的步骤进一步封装,让它更简单!

源码如下:

YXLocationManager.h + YXLocationManager.m

////  YXLocationManager.h//  MoreMapInfo////  Copyright (c) 2014年 Y.X. All rights reserved.//#import 
#import
typedef void(^locationBlock_t)(CLLocation* location, NSError *error);@interface YXLocationManager : NSObject+ (void)getCurrentLocation:(locationBlock_t)locationBlock;@end
////  YXLocationManager.m//  MoreMapInfo////  Copyright (c) 2014年 Y.X. All rights reserved.//#import "YXLocationManager.h"#import "AKLocationManager.h"@implementation YXLocationManager+ (void)getCurrentLocation:(locationBlock_t)locationBlock{    // 设置定位精度(这个是必须设置的,否则无法定位)    [AKLocationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];        // 设置超时时间    [AKLocationManager setTimeoutTimeInterval:10];        // 先结束获取坐标    [AKLocationManager stopLocating];        // 开始定位坐标    [AKLocationManager startLocatingWithUpdateBlock:^(CLLocation* location)     {         locationBlock(location, nil);              }failedBlock:^(NSError *error)     {         locationBlock(nil, error);     }];}@end

是不是很简单呢:).

 

 

附录:

// 动画定位到自身位置

            [self.mapView setCenterCoordinate:location.coordinate

                                     animated:YES];

 

转载地址:http://ehprl.baihongyu.com/

你可能感兴趣的文章
jQuery的使用
查看>>
jquery.fileupload 批量上传
查看>>
hdu A strange lift
查看>>
Gym-100676F Palindrome
查看>>
DS博客作业03--栈和队列
查看>>
Windows 10 to Go
查看>>
关于函数的原型对象笔记
查看>>
转:深入浅出空间索引:为什么需要空间索引
查看>>
IC卡读卡器web开发,支持IE,Chrome,Firefox,Safari,Opera等主流浏览 器
查看>>
CSS3: box-sizing 属性的简单认识
查看>>
Python3.2 --- Print函数用法
查看>>
常用工具说明--Java的常用工具
查看>>
C++中几个值得分析的小问题(1)
查看>>
【LeetCode 104_二叉树_遍历】Maximum Depth of Binary Tree
查看>>
Android zxing扫描二维码 为什么有些机型扫描不出来或者很慢?
查看>>
js-循环执行一个函数
查看>>
HDU 4720 Naive and Silly Muggles (简单计算几何)
查看>>
linux终端快捷键
查看>>
基础数据类型的补充和深浅copy
查看>>
20160327javaweb 之JSP入门
查看>>