码迷,mamicode.com
首页 > 其他好文 > 详细

地图位置信息

时间:2015-09-23 17:19:02      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:获取位置信息


//创建位置服务对象

    locationManager = [[CLLocationManager alloc] init];

    

    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    

    //设置定位代理

    locationManager.delegate = self;

    

    //如果实在iOS8.0之后,我们需要添加以下操作

    //1.调用方法--requestWhenInUseAuthorization 或者 requestAlwaysAuthorization

    //2.

    

    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {

        [locationManager requestWhenInUseAuthorization];

    }

    

    //开始定位

    [locationManager startUpdatingLocation];

    

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark -CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

{

    NSLog(@"定位成功");

    //停止定位

    [locationManager stopUpdatingLocation];

    

    CLLocationCoordinate2D coordinate = newLocation.coordinate;

    

    NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude);

    

}


- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations

{

    NSLog(@"新方法定位成功");

    //停止定位

    [locationManager stopUpdatingLocation];

    

    CLLocation *location = [locations lastObject];

    

    CLLocationCoordinate2D coordinate = location.coordinate;


    NSLog(@"位置:纬度:%.2f----经度:%.2f", coordinate.latitude, coordinate.longitude);


}


地图位置信息

标签:获取位置信息

原文地址:http://10554237.blog.51cto.com/10544237/1697422

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!