Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arnieterm

macrumors regular
Original poster
Aug 28, 2008
201
0
Inside the app delegate of an iphone application, I have declared a protocol as given below:
Code:
@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:
Code:
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:
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:

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

In the .m file of this viewcontroller, I have written:
Code:
-(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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
You don't declare method names like this
Code:
-(void) locationChanged:(float)newlatitude:(float)newlongitude
You need to split the parameters up like this
Code:
-(void) locationChangedToLatitude:(float)newlatitude longitude:(float)newlongitude
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
You don't declare method names like this
Code:
-(void) locationChanged:(float)newlatitude:(float)newlongitude
You need to split the parameters up like this
Code:
-(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

macrumors regular
Original poster
Aug 28, 2008
201
0
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

Code:
-(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

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.