0

I am trying to create a NSObject that will get the location and the address, I will also be running some other code. I want to just throw it into my different apps. I am having issues with it updating the location. I have the protocol and delegate working, but I will post all my code to try to make it clear.

In my getLocation.h

@protocol getLocationDelegate
- (void)getLocation:(NSString *)address getLongitude:(CGFloat)longitude getLatitude:(CGFloat)latitude;
@end

@interface getLocation : NSObject <CLLocationManagerDelegate> {
    CGFloat latitude;
    CGFloat longitude;
    NSString *address;

}

@property (nonatomic, strong) id<getLocationDelegate> delegate;
@property (nonatomic, retain) CLLocationManager *locationManager;

- (void)getLocationInfo;

In my getLocation.m

- (id)init
{
    if (self = [super init]) {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;


    }
    return self;
}

- (void)getLocationInfo {

    [self.locationManager startUpdatingLocation];
 // This is being called but not starting the locationManager
}

After I get the address and the location I call the protocol like this, in my getLocation.h

[self.delegate getLocation:address getLongitude:longitude getLatitude:latitude];

In my .m file that I want to get the location this is the code

getLocation *location = [[getLocation alloc] init];
[location setDelegate:self];
[location getLocationInfo];

Then I have my method when the delegate gets called

-(void)getLocation:(NSString *)address getLongitude:(CGFloat)longitude getLatitude:(CGFloat)latitude {
     // Do code after location and address has been returned
}

Now my protocol and delegate are working what my problem is I can't get the locationManager to start updating. Not sure whats going on.

4

1 回答 1

0

我想通了,ARC 是getLocation *location = [[getLocation alloc] init];在 CoreLocation 开始之前发布的。所以我只需要在我的 .h 中声明它并让它变得强大。

于 2013-03-06T14:58:24.347 回答