码迷,mamicode.com
首页 > 移动开发 > 详细

获取手机当前经纬度的方法

时间:2015-01-06 13:39:46      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

首先头文件应继承CLLocationManagerDelegate.
并:#import <CoreLocation/CoreLocation.h>

响应事件中写如下代码:
CLLocationManager *_locManager = [[CLLocationManager alloc] init]; 
[_locManager setDelegate:self]; 
[_locManager setDesiredAccuracy:kCLLocationAccuracyBest];    
[_locManager startUpdatingLocation];

重载
#pragma mark -
#pragma mark Location manager
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    CLLocationCoordinate2D loc = [newLocation coordinate];
    NSString *lat =[NSString stringWithFormat:@"%f",loc.latitude];//get latitude
    NSString *lon =[NSString stringWithFormat:@"%f",loc.longitude];//get longitude    
    NSLog(@"%@ %@",lat,lon);
}

获取手机当前经纬度的方法

标签:

原文地址:http://www.cnblogs.com/kelejiabing/p/4205762.html

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