0

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

4

1 回答 1

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];
}
于 2013-04-01T05:22:42.610 回答