iOS 地图定位
2016-02-18 11:45
387 查看
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface ViewController : UIViewController<CLLocationManagerDelegate> @property (retain, nonatomic) IBOutlet UITextField *latTxt; @property (retain, nonatomic) IBOutlet UITextField *lontTxt; @property (retain, nonatomic) IBOutlet UITextField *heighttxt; @end #import "ViewController.h" @interface ViewController () //定位管理 @property(nonatomic,retain)CLLocationManager *locationManager; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.locationManager=[[[CLLocationManager alloc] init] autorelease]; _locationManager.delegate=self; _locationManager.desiredAccuracy=kCLLocationAccuracyBest;//设备使用电池的。 _locationManager.distanceFilter=1000.0; // Do any additional setup after loading the view, typically from a nib. } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; //开始定位 [_locationManager startUpdatingLocation]; } -(void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear: animated]; //停止定位 [_locationManager stopUpdatingLocation]; } #pragma mark -locationManager delegate -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"--->%@",locations); CLLocation *location=[locations lastObject]; self.latTxt.text=[NSString stringWithFormat:@"%3.5f",location.coordinate.latitude]; self.lontTxt.text=[NSString stringWithFormat:@"%3.5f",location.coordinate.longitude]; self.heighttxt.text=[NSString stringWithFormat:@"%3.5f",location.altitude]; } -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"--error-->%@",error.localizedDescription); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [_locationManager release]; [_latTxt release]; [_lontTxt release]; [_heighttxt release]; [super dealloc]; }
相关文章推荐
- 2016.2.14苹果开发者证书无效
- iOS 为视图添加抖动效果
- iOS base64
- iOS应用图标及尺寸
- iOS 页面间几种传值方式(属性,代理,block,单例,通知)
- iOS加密
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- 需求 - 18 - “点赞动画”
- iOS通过 JSPatch实现 app的热更新
- iOS 实现应用之间的跳转
- iOS 52个技巧学习心得笔记 第一章 熟悉OC
- iOS环信3.0集成 (三)单聊集成
- 常用iOS第三方库以及XCode插件介绍
- iOS之OSX EI Capitan打包二进制文件提交审核失败
- iOS从plist文件里面读取内容
- iOS-代码提示如NS_AVAILABLE_IOS(4_2)的解释
- Metal-IOS-通用GPU计算:Data-Parallel Compute Processing: Compute Command Encoder
- iOS中本地化字符串
- Mac环境下svn的使用
- 分享 iOS