亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: iOS 8 實現(xiàn)獲取當(dāng)前定位信息 [打印本頁]

作者: nopower    時間: 2015-06-30 09:46
標(biāo)題: iOS 8 實現(xiàn)獲取當(dāng)前定位信息
iOS 8 實現(xiàn)獲取當(dāng)前定位信息

源碼:https://git.oschina.net/laughingzhong/LocationDemo.git

獲取當(dāng)前定位信息代碼
  1. //
  2. //  ViewController.m
  3. //  LocationDemo
  4. //
  5. //  Created by LaughingZhong on 14/11/12.
  6. //  Copyright (c) 2014年 Laughing. All rights reserved.
  7. //

  8. #import "ViewController.h"

  9. @interface ViewController ()

  10. @end

  11. @implementation ViewController
  12. @synthesize myLocationManager,myGeocoder,myLocation;

  13. - (void)dealloc
  14. {
  15.     self.myLocationManager = nil;
  16.     self.myLocation = nil;
  17.     self.myGeocoder = nil;
  18. }

  19. - (void)viewDidLoad {
  20.     [super viewDidLoad];
  21.     // Do any additional setup after loading the view from its nib.
  22.     if ([CLLocationManager locationServicesEnabled]) {
  23.         self.myLocationManager = [[CLLocationManager alloc] init];
  24.         [self.myLocationManager setDelegate:self];
  25.         self.myLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
  26.         self.myLocationManager.distanceFilter = 1.0;
  27. //        [self.myLocationManager requestAlwaysAuthorization];
  28.         [self.myLocationManager requestWhenInUseAuthorization];
  29.         [self.myLocationManager startUpdatingLocation];
  30.     }else {
  31.         NSLog(@"Location services are not enabled");
  32.     }
  33. }

  34. - (void)didReceiveMemoryWarning {
  35.     [super didReceiveMemoryWarning];
  36.     // Dispose of any resources that can be recreated.
  37. }

  38. #pragma mark -
  39. #pragma mark CLLocationManagerDelegate
  40. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
  41. {
  42.     NSLog(@"locations is %@",locations);
  43.     CLLocation *location = [locations lastObject];
  44.     self.myGeocoder = [[CLGeocoder alloc] init];
  45.     [self.myGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
  46.      {
  47.          if(error == nil && [placemarks count]>0)
  48.          {
  49.              CLPlacemark *placemark = [placemarks objectAtIndex:0];
  50.               
  51.              NSLog(@"name = %@",placemark.name);
  52.              NSLog(@"Country = %@", placemark.country);
  53.              NSLog(@"Postal Code = %@", placemark.postalCode);
  54.              NSLog(@"locality = %@", placemark.locality);
  55.              NSLog(@"subLocality = %@", placemark.subLocality);
  56.              NSLog(@"address = %@",placemark.name);
  57.              NSLog(@"administrativeArea = %@",placemark.administrativeArea);
  58.              NSLog(@"subAdministrativeArea = %@",placemark.subAdministrativeArea);
  59.              NSLog(@"ISOcountryCode = %@",placemark.ISOcountryCode);
  60.              NSLog(@"thoroughfare = %@", placemark.thoroughfare);
  61.              NSLog(@"subThoroughfare = %@",placemark.subThoroughfare);
  62.               
  63.              [label setText:[NSString stringWithFormat:@"address is: %@",placemark.name]];
  64.          }
  65.          else if(error==nil && [placemarks count]==0){
  66.              NSLog(@"No results were returned.");
  67.          }
  68.          else if(error != nil) {
  69.              NSLog(@"An error occurred = %@", error);
  70.          }
  71.      }];
  72.     [self.myLocationManager stopUpdatingLocation];
  73. }

  74. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
  75. {
  76.     NSLog(@"reverse geocoder error: %@", [error description]);
  77. }


  78. @end
復(fù)制代碼





歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2