首先头文件应继承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);
}
并:#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);
}
本文介绍如何在iOS应用中实现地理位置定位服务。通过设置CLLocationManager代理并调用相应方法,可以获取设备的精确经纬度坐标。
1797

被折叠的 条评论
为什么被折叠?



