• 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];
    }
  • 相关阅读:
    比较全的JS checkbox全选、取消全选、删除功能代码
    JS下高效拼装字符串的几种方法比较与测试代码
    jQuery操作 input type=checkbox的实现代码
    禁用和选中所有页面上的复选框。
    jquery实现radio按纽全不选和checkbox全选的实例
    Javascript的四种继承方式
    javascript绑定时间 含(IE)
    input中如何输入逆写的中文句子
    清除浮动
    关于iOS9中的App Transport Security相关说明及适配(转)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3271066.html
Copyright © 2020-2023  润新知