2009-07-08 4 views
0

Ich möchte meine geografische Länge und Breite auf dem iPhone in Ziel C bekommen. Kann mir jemand helfen, diese Koordinaten programmatisch zu bekommen?iPhone GPS Location

#import <Foundation/Foundation.h> 

@class CLLocationManager; 

@interface CLLocationController : NSObject { 
    CLLocationManager *locationManager; 
} 

@property (nonatomic, retain) CLLocationManager *locationManager; 

@end 

Wenn ich über Code zu schreiben ist, zeigt mir folgende Fehler

/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 die Dokumentation lesen – marcc

Antwort

2

die CLLocationManager verwenden, um ein Objekt als Delegierter gesetzt und starten Updates zu bekommen.

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

implementieren dann die Delegierten:

- (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]); 
} 
Verwandte Themen