Is there anything wrong with this?

Discussion in 'iOS Programming' started by arnieterm, Feb 25, 2009.

  1. macrumors regular

    Joined:
    Aug 28, 2008
    #1
    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
     
  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    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
    
     
  3. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #3
    The former is still a valid method signature. Have you confirmed that the locationManager:didUpdateToLocation:fromLocation: method is being called?
     
  4. thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #4
    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];
    	
    }
    
    
     
  5. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #5
    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?
     

Share This Page