IOS 定位 单例
时间:2014-04-29 10:12:46
收藏:0
阅读:534
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 |
+ (SCLocationController *)sharedController { static
SCLocationController *sharedController = nil ; static
dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedController = [[ self
alloc]init]; }); return
sharedController; } - ( id )init { self
= [ super
init]; if
( self ) { _locationManager = [[CLLocationManager alloc]init]; _locationManager.delegate = self ; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.distanceFilter = 30; // Meters. } return
self ; } #pragma mark - Location Manager #pragma mark - CLLocationManagerDelegate - ( void )locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [_locManager stopUpdatingLocation]; CLGeocoder *reverseGeocoder=[[CLGeocoder alloc] init]; [reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^( NSArray
*array, NSError
*error) { CLPlacemark *placeMark = [array lastObject]; if
(placeMark != nil ) { state = [placeMark.addressDictionary objectForKey:@ "State" ]; city = [placeMark.addressDictionary objectForKey:@ "City" ]; subLocality = [placeMark.addressDictionary objectForKey:@ "SubLocality" ]; if
(city.length > 0) { NSLog (@ "%@-%@-%@" ,state,city,subLocality); } else { NSLog (@ "%@-%@" ,state,subLocality); } } }]; } |
评论(0)