Commit aaf721b6 authored by yuzheng.tz's avatar yuzheng.tz

升级TZLocationManager,实现新的定位成功代理方法

parent 9da85019
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
/// 开始定位 /// 开始定位
- (void)startLocation; - (void)startLocation;
- (void)startLocationWithSuccessBlock:(void (^)(CLLocation *location,CLLocation *oldLocation))successBlock failureBlock:(void (^)(NSError *error))failureBlock; - (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock;
- (void)startLocationWithGeocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock; - (void)startLocationWithGeocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock;
- (void)startLocationWithSuccessBlock:(void (^)(CLLocation *location,CLLocation *oldLocation))successBlock failureBlock:(void (^)(NSError *error))failureBlock geocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock; - (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock geocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock;
@end @end
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
@interface TZLocationManager ()<CLLocationManagerDelegate> @interface TZLocationManager ()<CLLocationManagerDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager; @property (nonatomic, strong) CLLocationManager *locationManager;
/// 定位成功的回调block /// 定位成功的回调block
@property (nonatomic, copy) void (^successBlock)(CLLocation *location,CLLocation *oldLocation); @property (nonatomic, copy) void (^successBlock)(NSArray<CLLocation *> *);
/// 编码成功的回调block /// 编码成功的回调block
@property (nonatomic, copy) void (^geocodeBlock)(NSArray *geocodeArray); @property (nonatomic, copy) void (^geocodeBlock)(NSArray *geocodeArray);
/// 定位失败的回调block /// 定位失败的回调block
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
[self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:nil]; [self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:nil];
} }
- (void)startLocationWithSuccessBlock:(void (^)(CLLocation *location,CLLocation *oldLocation))successBlock failureBlock:(void (^)(NSError *error))failureBlock { - (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock {
[self startLocationWithSuccessBlock:successBlock failureBlock:failureBlock geocoderBlock:nil]; [self startLocationWithSuccessBlock:successBlock failureBlock:failureBlock geocoderBlock:nil];
} }
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
[self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:geocoderBlock]; [self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:geocoderBlock];
} }
- (void)startLocationWithSuccessBlock:(void (^)(CLLocation *location,CLLocation *oldLocation))successBlock failureBlock:(void (^)(NSError *error))failureBlock geocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock { - (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock geocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock {
[self.locationManager startUpdatingLocation]; [self.locationManager startUpdatingLocation];
_successBlock = successBlock; _successBlock = successBlock;
_geocodeBlock = geocoderBlock; _geocodeBlock = geocoderBlock;
...@@ -57,16 +57,16 @@ ...@@ -57,16 +57,16 @@
#pragma mark - CLLocationManagerDelegate #pragma mark - CLLocationManagerDelegate
/// 地理位置发生改变时触发 /// 地理位置发生改变时触发
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
[manager stopUpdatingLocation]; [manager stopUpdatingLocation];
if (_successBlock) { if (_successBlock) {
_successBlock(newLocation,oldLocation); _successBlock(locations);
} }
if (_geocodeBlock) { if (_geocodeBlock && locations.count) {
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *array, NSError *error) { [geocoder reverseGeocodeLocation:[locations firstObject] completionHandler:^(NSArray *array, NSError *error) {
_geocodeBlock(array); _geocodeBlock(array);
}]; }];
} }
......
...@@ -585,9 +585,9 @@ static CGFloat itemMargin = 5; ...@@ -585,9 +585,9 @@ static CGFloat itemMargin = 5;
- (void)pushImagePickerController { - (void)pushImagePickerController {
// 提前定位 // 提前定位
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) { [[TZLocationManager manager] startLocationWithSuccessBlock:^(NSArray<CLLocation *> *locations) {
__strong typeof(weakSelf) strongSelf = weakSelf; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location; strongSelf.location = [locations firstObject];
} failureBlock:^(NSError *error) { } failureBlock:^(NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil; strongSelf.location = nil;
......
...@@ -370,9 +370,9 @@ ...@@ -370,9 +370,9 @@
- (void)pushImagePickerController { - (void)pushImagePickerController {
// 提前定位 // 提前定位
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) { [[TZLocationManager manager] startLocationWithSuccessBlock:^(NSArray<CLLocation *> *locations) {
__strong typeof(weakSelf) strongSelf = weakSelf; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location; strongSelf.location = [locations firstObject];
} failureBlock:^(NSError *error) { } failureBlock:^(NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil; strongSelf.location = nil;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment