iOS开发中位置定位的封装开发

2016-02-10  本文已影响965人  df837e5ea60a

在很多的APP开发中经常使用到定位功能,对于这种常用的方法很有必要对其封装使用

话不多说直接上代码:使用到了单例设计模式:
`

import <Foundation/Foundation.h>

import <MapKit/MapKit.h>

@protocol PositionToolDelegate <NSObject>

@optional
/**

@end

@interface PositionTool : NSObject<CLLocationManagerDelegate,PositionToolDelegate> {
CLLocationManager *_locationManager;
NSMutableArray *_locationArr ;
}

@property (nonatomic,assign) CLLocationDegrees latitude;//经度
@property (nonatomic,assign) CLLocationDegrees longtitude;//纬度
/**

//@property (nonatomic,strong) id<PositionToolDelegate> delegate;

/**

/**

@end
.m方法的实现

/**

pragma mark ========= 获取位置 ==========

pragma mark - 调用地图代理方法

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"aaa%@", @"ok");
}
`
使用时候直接在使用到的地方加入
[[PositionTool shareInfo] getLocation];

上一篇 下一篇

猜你喜欢

热点阅读