Reputation:
I want to get my longitude and latitude on iPhone in objective C. Can any one guide me how to get these coordinates programmatically?
#import <Foundation/Foundation.h>
@class CLLocationManager;
@interface CLLocationController : NSObject {
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
When i write above code is shows me following errors
/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
Upvotes: 0
Views: 1809
Reputation: 8836
Use the CLLocationManager, set an object as the delegate and start getting updates.
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
Then implement the delegate:
- (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]);
}
Upvotes: 2