Lat,Long值对于iphone中的当前位置不准确

时间:2013-01-31 09:16:40

标签: core-location mkmapview

我是新手IOS现在我正在开发位置应用程序我在iPhone中运行我的应用程序时没有获得正确的纬度,经度值..它给了我太远的lat,长值到当前位置为什么它显示我这些值任何人都可以告诉我..

1 个答案:

答案 0 :(得分:0)

试试吧......

设置委托CLLocationManagerDelegate

#import <CoreLocation/CoreLocation.h>

CLLocationManager *locationManager;
CLLocation *startLocation;


- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *currentLatitude;
    NSString *currentLongitude;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    startLocation = nil;
 }

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    currentLatitude = [[NSString alloc] 
                   initWithFormat:@"%g", 
                   newLocation.coordinate.latitude];



    currentLongitude = [[NSString alloc] 
                    initWithFormat:@"%g",
                    newLocation.coordinate.longitude];

   NSLog(@"%@",currentLatitude);
   NSLog(@"%@",currentLongitude);
}

-(void)locationManager:(CLLocationManager *)manager 
  didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"%@",error] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}