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];
    }
  • 相关阅读:
    ios 视频旋转---分解ZFPlayer
    IOS lame库 pcm转mp3 分析(方案二)
    IOS lame库 pcm转mp3 分析(方案一)
    ios 动态库合成包(真机&模拟器)脚本
    lame 制作ios静态库
    React Native scrollview 循环播放
    React Native Image多种加载图片方式
    汉字转拼音(包含多音字)
    React Native Alert、ActionSheet
    React Native Picker (城市选择器)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3271066.html
Copyright © 2011-2022 走看看