#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
@synthesize locationManager;
@synthesize startingPoint;
@synthesize latitudeLabel;
@synthesize longitudeLabel;
@synthesize horizontalAccuracyLabel;
@synthesize altitudeLabel;
@synthesize verticalAccuracyLabel;
@synthesize distanceTraveledLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor blackColor];
self.latitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 30, 200, 30)];
self.latitudeLabel.backgroundColor=[UIColor whiteColor];
self.longitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 70, 200, 30)];
self.longitudeLabel.backgroundColor=[UIColor whiteColor];
self.horizontalAccuracyLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 110, 200, 30)];
self.horizontalAccuracyLabel.backgroundColor=[UIColor whiteColor];
self.altitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 150, 200, 30)];
self.altitudeLabel.backgroundColor=[UIColor whiteColor];
self.verticalAccuracyLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 190, 200, 30)];
self.verticalAccuracyLabel.backgroundColor=[UIColor whiteColor];
self.distanceTraveledLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 230, 200, 30)];
self.distanceTraveledLabel.backgroundColor=[UIColor whiteColor];
[self.view addSubview:self.latitudeLabel];
[self.view addSubview:self.longitudeLabel];
[self.view addSubview:self.horizontalAccuracyLabel];
[self.view addSubview:self.altitudeLabel];
[self.view addSubview:self.verticalAccuracyLabel];
[self.view addSubview:self.distanceTraveledLabel];
self.locationManager=[[CLLocationManager alloc]init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
if (startingPoint==nil) {
self.startingPoint=[locations objectAtIndex:[locations count]-1];
NSString *latitude=[NSString stringWithFormat:@"%g\u00B0",self.startingPoint.coordinate.latitude];
latitudeLabel.text=latitude;
NSString *longitude=[NSString stringWithFormat:@"%g\u00B0",self.startingPoint.coordinate.longitude];
longitudeLabel.text=longitude;
NSString *horizontal=[NSString stringWithFormat:@"%gm",self.startingPoint.horizontalAccuracy];
horizontalAccuracyLabel.text=horizontal;
NSString *altitude=[NSString stringWithFormat:@"%gm",self.startingPoint.altitude];
altitudeLabel.text=altitude;
NSString *vertical=[NSString stringWithFormat:@"%gm",self.startingPoint.verticalAccuracy];
verticalAccuracyLabel.text=vertical;
CLLocationDirection distance=[self.startingPoint distanceFromLocation:startingPoint];
NSString *distances=[NSString stringWithFormat:@"%gm",distance];
distanceTraveledLabel.text=distances;
}
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSString *errorType=(error.code==kCLErrorDenied)?@"Access Denide":@"Unknown Error";
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error getting Location" message:errorType delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[alert show];
}
@end
@interface RootViewController ()
@end
@implementation RootViewController
@synthesize locationManager;
@synthesize startingPoint;
@synthesize latitudeLabel;
@synthesize longitudeLabel;
@synthesize horizontalAccuracyLabel;
@synthesize altitudeLabel;
@synthesize verticalAccuracyLabel;
@synthesize distanceTraveledLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor blackColor];
self.latitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 30, 200, 30)];
self.latitudeLabel.backgroundColor=[UIColor whiteColor];
self.longitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 70, 200, 30)];
self.longitudeLabel.backgroundColor=[UIColor whiteColor];
self.horizontalAccuracyLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 110, 200, 30)];
self.horizontalAccuracyLabel.backgroundColor=[UIColor whiteColor];
self.altitudeLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 150, 200, 30)];
self.altitudeLabel.backgroundColor=[UIColor whiteColor];
self.verticalAccuracyLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 190, 200, 30)];
self.verticalAccuracyLabel.backgroundColor=[UIColor whiteColor];
self.distanceTraveledLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 230, 200, 30)];
self.distanceTraveledLabel.backgroundColor=[UIColor whiteColor];
[self.view addSubview:self.latitudeLabel];
[self.view addSubview:self.longitudeLabel];
[self.view addSubview:self.horizontalAccuracyLabel];
[self.view addSubview:self.altitudeLabel];
[self.view addSubview:self.verticalAccuracyLabel];
[self.view addSubview:self.distanceTraveledLabel];
self.locationManager=[[CLLocationManager alloc]init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
if (startingPoint==nil) {
self.startingPoint=[locations objectAtIndex:[locations count]-1];
NSString *latitude=[NSString stringWithFormat:@"%g\u00B0",self.startingPoint.coordinate.latitude];
latitudeLabel.text=latitude;
NSString *longitude=[NSString stringWithFormat:@"%g\u00B0",self.startingPoint.coordinate.longitude];
longitudeLabel.text=longitude;
NSString *horizontal=[NSString stringWithFormat:@"%gm",self.startingPoint.horizontalAccuracy];
horizontalAccuracyLabel.text=horizontal;
NSString *altitude=[NSString stringWithFormat:@"%gm",self.startingPoint.altitude];
altitudeLabel.text=altitude;
NSString *vertical=[NSString stringWithFormat:@"%gm",self.startingPoint.verticalAccuracy];
verticalAccuracyLabel.text=vertical;
CLLocationDirection distance=[self.startingPoint distanceFromLocation:startingPoint];
NSString *distances=[NSString stringWithFormat:@"%gm",distance];
distanceTraveledLabel.text=distances;
}
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSString *errorType=(error.code==kCLErrorDenied)?@"Access Denide":@"Unknown Error";
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error getting Location" message:errorType delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[alert show];
}
@end