2009-07-08 20 views
0

iPhoneで私の経度と緯度を目標Cで取得したいと思います。これらの座標をプログラムで取得する方法を教えてもらえますか?iPhone GPSの場所

#import <Foundation/Foundation.h> 

@class CLLocationManager; 

@interface CLLocationController : NSObject { 
    CLLocationManager *locationManager; 
} 

@property (nonatomic, retain) CLLocationManager *locationManager; 

@end 

私は上記のコード記述され、エラー

/Hab/Folder/Classes/CLLocationController.m:10:30: error: CLLocationManager.h: No such file or directory 
/Hab/Folder/Classes/CLLocationController.m:21: warning: receiver 'CLLocationManager' is a forward class and corresponding @interface may not exist 
/Hab/Folder/Classes/CLLocationController.m:22: error: accessing unknown 'delegate' component of a property 
+1

developer.apple.com:

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; [self.locationManager startUpdatingLocation]; 

その後、デリゲートを実装 – marcc

答えて

2

、CLLocationManagerを使用してデリゲートとしてオブジェクトを設定し、更新情報を取得を開始、次の私を示しています。ドキュメントを読んで

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { 
    NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]); 
    NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]); 
}