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

  • 相关阅读:
    linux查看硬件信息及驱动设备相关整理
    qt 画图相关
    glaux.h vs2008
    技巧:Vimdiff 使用
    Linux下显示硬件信息(二)lshw
    Linux下硬件信息查看(一)dmidecode
    qt delegate
    RFKill 【解决opensuse11.4 无法开启无线网的问题】
    板子上运行提示 找不到qml插件
    CRISPDM
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3752449.html
Copyright © 2011-2022 走看看