zoukankan      html  css  js  c++  java
  • 使用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];

  • 相关阅读:
    C语言第三次博客作业---单层循环结构
    C语言第二次博客作业---分支结构
    C语言第一次博客作业
    第0次作业
    第09组 Beta冲刺(1/5)
    第09组 Alpha事后诸葛亮
    第09组 Alpha冲刺(6/6)
    第09组 Alpha冲刺(5/6)
    第09组 Alpha冲刺(4/6)
    第09组 Alpha冲刺(3/6)
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3752449.html
Copyright © 2011-2022 走看看