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

  • 相关阅读:
    Rabbitmq的使用四_Java Client方式使用Topic模式
    CentOS7安装Redis
    nmon文件结果分析
    nmon安装
    jmeter+ant+jenkins
    jenkins插件下载加速
    jmeter:多机联合负载
    jmeter Linux负载机出错Server failed to start:
    jenkins安装
    fiddler:筛选请求响应
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3752449.html
Copyright © 2011-2022 走看看