You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
![]()
2 years ago
|
//
|
||
|
// XHLocationHelper.m
|
||
|
// MessageDisplayExample
|
||
|
//
|
||
|
// Created by HUAJIE-1 on 14-5-8.
|
||
|
// Copyright (c) 2014年 嗨,我是曾宪华(@xhzengAIB),曾加入YY Inc.担任高级移动开发工程师,拍立秀App联合创始人,热衷于简洁、而富有理性的事物 QQ:543413507 主页:http://zengxianhua.com All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "XHLocationHelper.h"
|
||
|
|
||
|
@interface XHLocationHelper () <CLLocationManagerDelegate>
|
||
|
|
||
|
@property (nonatomic, strong) CLLocationManager *locationManager;
|
||
|
|
||
|
@property (nonatomic, copy) DidGetGeolocationsCompledBlock didGetGeolocationsCompledBlock;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation XHLocationHelper
|
||
|
|
||
|
- (void)setup {
|
||
|
_locationManager = [[CLLocationManager alloc] init];
|
||
|
_locationManager.delegate = self;
|
||
|
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
|
||
|
_locationManager.distanceFilter = 5.0;
|
||
|
}
|
||
|
|
||
|
- (id)init {
|
||
|
self = [super init];
|
||
|
if (self) {
|
||
|
[self setup];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)dealloc {
|
||
|
self.locationManager.delegate = nil;
|
||
|
self.locationManager = nil;
|
||
|
self.didGetGeolocationsCompledBlock = nil;
|
||
|
}
|
||
|
|
||
|
- (void)getCurrentGeolocationsCompled:(DidGetGeolocationsCompledBlock)compled {
|
||
|
self.didGetGeolocationsCompledBlock = compled;
|
||
|
[self.locationManager startUpdatingLocation];
|
||
|
}
|
||
|
|
||
|
#pragma mark - CLLocationManager Delegate
|
||
|
|
||
|
// 代理方法实现
|
||
|
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
|
||
|
CLGeocoder* geocoder = [[CLGeocoder alloc] init];
|
||
|
|
||
|
[geocoder reverseGeocodeLocation:newLocation completionHandler:
|
||
|
^(NSArray* placemarks, NSError* error) {
|
||
|
if (self.didGetGeolocationsCompledBlock) {
|
||
|
self.didGetGeolocationsCompledBlock(placemarks);
|
||
|
}
|
||
|
}];
|
||
|
[manager stopUpdatingLocation];
|
||
|
}
|
||
|
|
||
|
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
|
||
|
[manager stopUpdatingLocation];
|
||
|
}
|
||
|
|
||
|
@end
|