• 获取当前位置


    http://stackoverflow.com/questions/3535800/cllocationmanager-strange-memory-leak

    #import <Foundation/Foundation.h>

    #import <CoreLocation/CoreLocation.h>

    @protocol MapLocationManagerDelegate 

    @required

    - (void)locationUpdate:(CLLocation *)location;

    - (void)locationError:(NSError *)error;

    @end

    @interface MapLocationManager : NSObject <CLLocationManagerDelegate>{

    CLLocationManager *locationManage;

    id delegate;

    }

    @property (nonatomic, retain) CLLocationManager *locationManage;

    @property (nonatomic, assign) id delegate;

    @end

    /*  

    //调用例子

     h文件

     #import <UIKit/UIKit.h>

     

     #import "CoreLocationController.h"

     

     @interface CoreLocationDemoViewController : UIViewController <MapLocationManagerDelegate > {

     MapLocationManager *CLController;

     IBOutlet UILabel *locLabel;

     }

     

     @property (nonatomic, retain)  MapLocationManager *CLController;

     

     @end

     

     m文件

     

     - (void)viewDidLoad {

     [super viewDidLoad];

     

     CLController = [[ MapLocationManager alloc] init];

     CLController.delegate = self;

     [CLController.locMgr startUpdatingLocation];

     }

     

     - (void)locationUpdate:(CLLocation *)location {

     locLabel.text = [location description];

     }

     

     - (void)locationError:(NSError *)error {

     locLabel.text = [error description];

     }

     

     - (void)didReceiveMemoryWarning {

     [super didReceiveMemoryWarning];

     }

     

     

     - (void)dealloc {

     [CLController release];

     [super dealloc];

     }

     

    */

    m

    #import "MapLocationManage.h"

    @implementation MapLocationManager

    @synthesize locationManage, delegate;

    - (id) init {

    self = [super init];

    if(self != nil) {

    self.locationManage = [[[CLLocationManager alloc] init] autorelease];

    self.locationManage.delegate = self;

    [self performSelector:@selector(stopUpdate) withObject:@"Timed Out" afterDelay:10.0];

    }

    return self;

    }

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

    {

    if([self.delegate conformsToProtocol:@protocol(MapLocationManagerDelegate)]) {

    [self.delegate locationUpdate:newLocation];

    }

    }

    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{

    if([self.delegate conformsToProtocol:@protocol(MapLocationManagerDelegate)]) {

    [self.delegate locationError:error];

    }

    }

    -(void)stopUpdate

    {

    [self.locationManage stopUpdatingLocation];

    }

    - (void)dealloc {

        [self.locationManage release];

    [super dealloc];

    }

    @end

  • 相关阅读:
    解决:transform-decorators-legacy 报错
    leetcode刷题笔记 232题 用栈实现队列
    leetcode刷题笔记 231题 2的幂
    leetcode刷题笔记 230题 二叉搜索树中第K小的元素
    leetcode刷题笔记 229题 求众数II
    leetcode刷题笔记 228题 汇总区间
    leetcode刷题笔记 227题 基本计算器II
    leetcode刷题笔记 225题 用队列实现栈
    leetcode刷题笔记 224题 基本计算器
    leetcode刷题笔记 223题 矩形面积
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175605.html
Copyright © 2020-2023  润新知