私はIOSを初めて使用し、ロケーションアプリを開発しています。iPhoneでアプリを実行しているときに正しい緯度、経度の値を取得できません。現在のロケーションに対して緯度と経度の値が遠すぎます。これらの値が表示される理由は誰でもわかります。自分..
質問する
163 次
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 に答える