使用AKLocationManager定位

简介:

使用AKLocationManager定位

https://github.com/ideaismobile/AKLocationManager

 

以下是使用情况:

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

源码如下:

YXLocationManager.h + YXLocationManager.m

//
//  YXLocationManager.h
//  MoreMapInfo
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

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];

目录
相关文章
|
11月前
定位有几种,他们的特点分别是什么? 是相对于什么进行定位的?
定位有几种,他们的特点分别是什么? 是相对于什么进行定位的?
80 0
|
2月前
定位
【8月更文挑战第25天】定位。
43 3
|
11天前
定位有几种,他们的特点分别是什么?是相对于什么进行定位的?
定位有几种,他们的特点分别是什么?是相对于什么进行定位的?
11 0
|
1月前
静态定位和固定定位
静态定位和固定定位。
23 1
|
IDE 前端开发 安全
使用xpath定位遇到的坑
使用xpath定位遇到的坑
215 0
测试定位打卡
测试定位打卡
62 0
|
XML 数据格式 开发者
|
存储 中间件 测试技术
如何及时定位到非必现问题?
自定义channel;区分哪个环境中使用自定义的channel;使用优雅的 monolog 驱动
160 0
如何及时定位到非必现问题?
|
安全 开发者
定位 | 学习笔记
快速学习定位。
定位 | 学习笔记
文件定位
文件定位
108 0