PDA

View Full Version : Is there anything wrong with this?




arnieterm
Feb 25, 2009, 09:48 AM
Inside the app delegate of an iphone application, I have declared a protocol as given below:

@protocol UILocationDelegate <NSObject>
@required
-(void) locationChanged:(float)newlatitude:(float)newlongitude;
@end

There is an instance of CLLocationManager inside the app delegate with property as given below:

CLLocationManager* locationManager;
id delegate;

@property(nonatomic,retain)CLLocationManager* locationManager;
@property (nonatomic,assign) id <UILocationDelegate> delegate;


After synthesizing all the required fields, I have used the below given code:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{

[self.delegate locationChanged:newLocation.coordinate.latitude:newLocation.coordinate.longitude];
}



In another view controller, I hae implemented the UILocationDelegate as given below:


@interface UIMyController : UIViewController <UIAlertViewDelegate,UILocationDelegate,UIScrollViewDelegate>


In the .m file of this viewcontroller, I have written:

-(void) locationChanged:(float)newlatitude:(float)newlongitude
{



}

Is there anything wrong with the above given logic as I want to handle the callbacks from the CLLocationManager but the event in the above viewcontroller is not getting raised.

Thanks
Arnieterm



caveman_uk
Feb 25, 2009, 01:31 PM
You don't declare method names like this

-(void) locationChanged:(float)newlatitude:(float)newlongitude

You need to split the parameters up like this

-(void) locationChangedToLatitude:(float)newlatitude longitude:(float)newlongitude

jnic
Feb 26, 2009, 03:53 AM
You don't declare method names like this

-(void) locationChanged:(float)newlatitude:(float)newlongitude

You need to split the parameters up like this

-(void) locationChangedToLatitude:(float)newlatitude longitude:(float)newlongitude


The former is still a valid method signature. Have you confirmed that the locationManager:didUpdateToLocation:fromLocation: method is being called?

arnieterm
Feb 26, 2009, 06:08 AM
The former is still a valid method signature. Have you confirmed that the locationManager:didUpdateToLocation:fromLocation: method is being called?

Yes I have confirmed, it is not being called and also the LocationServices is enabled [turned on] in Settings. Instead I am getting the event "didFailWithError" with strError=@"Unknown location error". My iphone do not have any SIM and I am in India


-(void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString* strError;
if([error domain]==kCLErrorDomain)
{
switch([error code])
{
case kCLErrorDenied:
strError=@"Location denied error";
break;
case kCLErrorLocationUnknown:
strError=@"Unknown location error";
break;
default:
strError=@"Generic Location Error";
break;
}
}
else
{
strError=[@"Error doamin: " stringByAppendingString: error.domain];
strError=[ [ strError stringByAppendingString:@" Error Code: "]stringByAppendingString: [ [NSNumber numberWithInteger:error.code] stringValue ]];
}
//NSString* strError=[@"Error doamin: " stringByAppendingString: error.domain];
//strError=[ [ strError stringByAppendingString:@" Error Code: "]stringByAppendingString: [ [NSNumber numberWithInteger:error.code] stringValue ]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error:Location Services" message:strError delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error:Location Services" message:@"There is an error in getting the location details" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}

jnic
Feb 26, 2009, 06:36 AM
So the problem isn't with your delegate but with Core Location. Are other apps that rely on CL (e.g. Google Maps) working correctly for you?