Hello,
I have the following code in place:
NewWorkoutViewController.h
#import <UIKit/UIKit.h>
//#import <CoreLocation/CoreLocation.h>
#import <CoreData/CoreData.h>
#import "MapViewController.h"
#import "StatisticsViewController.h"
#import "MyCLController.h"
#import "Workout.h"
#import "Route.h"
@interface NewWorkoutViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate, UIAlertViewDelegate> {
MyCLController *locationController;
IBOutlet UIButton *saveButton;
IBOutlet UIButton *backButton;
IBOutlet UIButton *startButton;
IBOutlet UIButton *stopButton;
IBOutlet UIButton *resetButton;
IBOutlet MapViewController *mapViewController;
IBOutlet StatisticsViewController *statisticsViewController;
IBOutlet UIView *routePickerView;
IBOutlet UIPickerView *routePicker;
IBOutlet UIView *activityPickerView;
IBOutlet UIPickerView *activityPicker;
IBOutlet UIView *intensityPickerView;
IBOutlet UIPickerView *intensityPicker;
IBOutlet UILabel *time;
IBOutlet UITextField *route;
IBOutlet UITextField *activity;
IBOutlet UITextField *intensity;
IBOutlet UILabel *speed;
IBOutlet UILabel *distance;
IBOutlet UILabel *averageSpeed;
IBOutlet UILabel *calories;
NSMutableArray *routeArray;
NSMutableArray *activityArray;
NSMutableArray *intensityArray;
NSMutableArray *newWorkoutArray;
NSManagedObjectContext *managedObjectContext;
int counterInt;
NSTimer *myTimer;
NSInteger *startInterval;
NSInteger *stopInterval;
NSInteger *elapsedInterval;
NSString *mapID;
int pickerChoice;
NSString *walkID;
NSString *activityValue;
NSString *intensityValue;
CLLocation *currentlocation;
CLLocation *previouslocation;
//double kilometers;
//double totalkilometers;
}
@property (retain,nonatomic) NSMutableArray *newWorkoutArray;
@property (retain,nonatomic) NSTimer *myTimer;
@property (nonatomic,assign) NSManagedObjectContext *managedObjectContext;
-(IBAction)backButton;
-(IBAction)saveButton;
-(IBAction)mapButton;
-(IBAction)statisticsButton;
-(IBAction)startTimerButton;
-(IBAction)stopTimerButton;
-(IBAction)resetButton;
-(IBAction)routePickerShow;
-(IBAction)activityPickerShow;
-(IBAction)intensityPickerShow;
-(IBAction)routeDoneButton;
-(IBAction)activityDoneButton;
-(IBAction)intensityDoneButton;
-(void)showActivity;
-(void)didCreateWorkout:(NSString *)thisTime
Route:(NSString *)thisRoute
Activity:(NSString *)thisActivity
Intensity:(NSString *)thisIntensity
Speed:(NSString *)thisSpeed
Distance:(NSString *)thisDistance
AverageSpeed:(NSString *)thisAverageSpeed
Calories:(NSString *)thisCalories;
-(void)initialiseWorkoutViewController;
-(void)locationUpdate:(CLLocation *)location;
@end
NewWorkoutViewController.m
-(void)locationUpdate:(CLLocation *)location
{
currentlocation = [[CLLocation alloc] initWithLatitude:+37.364305 longitude:-122.027901];
previouslocation = [[CLLocation alloc] initWithLatitude:+37.364429 longitude:-122.028048]; //70301
if(previouslocation != nil) {
CLLocationDistance kilometers = [currentlocation distanceFromLocation:previouslocation]; // Error occurring here
NSLog(@"Distance Meters: %f", kilometers);
[speed setText:[NSString stringWithFormat:@"%.2f",[location speed]]];
[distance setText:[NSString stringWithFormat:@"%.2f", kilometers / 1000]];
previouslocation = currentlocation;
}
}
MyCLLocation.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@protocol MyCLControllerDelegate <NSObject>
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
@end
@interface MyCLController : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
id delegate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) id delegate;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
@end
MyCLLocation.m
#import "MyCLController.h"
@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // send loc updates to myself
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[self.delegate locationUpdate:newLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
[self.delegate locationError:error];
}
- (void)dealloc {
[self.locationManager release];
[super dealloc];
}
@end
I get the following error message on the CLLocationDistance line in NewWorkoutViewController.m "Incompatible types in initialization".
Anyone any thoughts ?
Regards, Stephen