获取当前经纬度方法

简介:
首先头文件应继承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);
}
目录
相关文章
|
9月前
|
定位技术
百度地图拾取经纬度转为标准GEOJSON格式的函数解决方案
百度地图拾取经纬度转为标准GEOJSON格式的函数解决方案
164 0
(二)GeoHash转经纬度
GeoHash转经纬度
1019 0
|
9月前
|
定位技术
百度地图开发:字符串经纬度转为经纬度数组的解决方案
百度地图开发:字符串经纬度转为经纬度数组的解决方案
73 0
|
4月前
|
Python
计算两个位置经纬度距离
计算两个位置经纬度距离
49 0
|
9月前
|
定位技术
百度拾取经纬度坐标转化的geojson数据偏离中心的解决方案
百度拾取经纬度坐标转化的geojson数据偏离中心的解决方案
96 0
|
SQL JSON Java
GPS坐标转换成百度坐标-如何解析json返回值
GPS坐标转换成百度坐标-如何解析json返回值
246 0