views:

166

answers:

1

Hey Guys I have the following simple Code : WhereAmIViewController.h

    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>

    @interface WhereAmIViewController : UIViewController <CLLocationManagerDelegate> {

        CLLocationManager *locationManager;
        CLLocation *startingPoint;
        IBOutlet UILabel *latitudeLabel;
        IBOutlet UILabel *longitudeLabel;
        IBOutlet UILabel *magneticHeading;
    }
    @property (retain, nonatomic) CLLocationManager *locationManager;
    @property (retain, nonatomic) CLLocation *startingPoint;
    @property (retain, nonatomic) UILabel *latitudeLabel;
    @property (retain, nonatomic) UILabel *longitudeLabel;
    @property (nonatomic, retain) UILabel *magneticHeading;

@end

WhereAmIViewController.m

#import "WhereAmIViewController.h"

@implementation WhereAmIViewController
@synthesize locationManager;
@synthesize startingPoint;
@synthesize latitudeLabel;
@synthesize longitudeLabel;
@synthesize magneticHeading;


- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{

    NSString *magneticstring = [[NSString alloc] initWithFormat:@"%0.0f°",
                                newHeading.magneticHeading];
    magneticHeading.text = magneticstring;
    [magneticstring release];
}




#pragma mark -
-(void)viewDidLoad
{
    self.locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    [locationManager startUpdatingHeading];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [locationManager release];
    [startingPoint release];
    [latitudeLabel release];
    [longitudeLabel release];
    [super dealloc];
}
#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
-(void)locationManager:(CLLocationManager *)manger
        didUpdateToLocation:(CLLocation *)newLocation
        fromLocation:(CLLocation *)oldLocation
{

    if(startingPoint == nil)
        self.startingPoint = newLocation;

    NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
    latitudeLabel.text = latitudeString;
    [latitudeString release];
    NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
    longitudeLabel.text = longitudeString;
    [longitudeString release];

}

-(void)longitudeManager:(CLLocationManager *)manager
                         didFailWithError:(NSError *)error
{
                             NSString *errorType = (error.code ==kCLErrorDenied)?@"Access Denied":@"Unknown Error";
                             UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error Getting Location!" message:errorType delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                             [alert show];
                             [alert release];
}

@end

So that's what I am displaying on screen .. I just wanted to know how get these 3 labels as an overview for the camera . I have refered to http://www.musicalgeometry.com/archives/821 But having trouble as mine is "View Based app" and the tutorial uses a "Windows Based app" template .. How can I configure this code to get the camera overlay ? P.S: The background color is : noColor (transparent ).

Thank You !

A: 

You need a UIImagePickerController, and then you create a UIView and add your 3 labels in appropriate locations in subview then you can call, picker.cameraOverlayView = YOUR_UI_VIEW and picker.showsCameraControls = NO. If you already set up everything inside your WhereAmIViewController then you can do picker.cameraOverlayView = whereAmIVC.view

vodkhang