zoukankan      html  css  js  c++  java
  • ios中地图定位

    #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];
    }
  • 相关阅读:
    Scite 编辑器及其相关项目介绍
    cmake 常用指令入门指南
    C++中的POD类型
    引用折叠、万能引用和完美转发那些事
    c++的对象初始化
    C++类对象的内存布局
    effective C++ 读书精华笔记提取
    c/c++的const说明符——深入挖掘
    gdb调试器—常用知识(一)
    g++/gcc编译器——常用知识(一)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3271066.html
Copyright © 2011-2022 走看看