在iOS中尝试使用核心定位框架以获取精确的GPS位置,但是一直无法获得准确的位置信息。即使使用苹果地图和谷歌地图也无法指向正确的位置。以下是我正在使用的代码片段:
MyLocation类头文件
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface MyLocation : NSObject<CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
MyLocation类m文件
#import "MyLocation.h"
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
@implementation MyLocation
@synthesize curLocation;
-(id)init{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
locationManager.distanceFilter = 0;
//locationManager.distanceFilter = kCLDistanceFilterNone;
//locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self updateLocation];
curLocation = CGPointZero;
return self;
}
-(void)updateLocation{
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
curLocation = CGPointMake( newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}