简体   繁体   中英

How can I integrate core location data to my blank iPhone App without introducing View or tab controller?

How can I integrate core location data (Lat, Long, Altitude) into my (single view) iPhone app without creating additional view controllers or tab controllers? in other words, when I run the app I want to see a blank screen (xView) but be able to collect (Longitude, Latitude information in the background and then maybe store the coordinates in a file or pass it on to a other functions. Sorry if this sounds like a dumb question. I am new to iOS development. Thanks.

HelloXYZAppDelegate.h:

#import <UIKit/UIkit.h>
#import "MyclassView.h"

@interface HelloXYZAppDelegate: NSObject <UIApplicationDelegate> 
{
  MyClassView* _xView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MyClassView *xView;

@end





HelloXYZAppDelegate.m

#import "HelloXYZAppDelegate.h"
@implementation HelloXYZAppDelegate
@synthesize xView=_xView;
@synthesize window=_window;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:      
{
 self.xView = [[[MyClassView alloc] initWithFrame:screenBounds] autorelease];
 [self.window addSubview:_xView];
 [self.window makeKeyAndVisible];
 return YES;
}

@end





MyClassView.h:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#include <OpenGLES/ES2/gl.h> 

@interface MyClassView : UIView 
{
CAEAGLLayer* _eaglLayer;
EAGLContext* _context;
GLuint _CRBuffer;
GLuint _PSlot;
....
....
....
CLLocationManager *LM;  //not sure if I can do this in here
CLLocation *SP;         //not sure if I can do this in here
}
@property (nonatomic, retain) CLLocationManager *LM;
@property (nonatomic, retain) CLLocation *SP;
@end





MyClassView.m

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation 
{
if (SP == nil)
    self.SP = newLocation;
NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g\u00B0",
                        newLocation.coordinate.latitude];
NSLog(@"latitude is %@", latitudeString);
    [latitudeString release];
}   

- (void)viewDidLoad
{
self.LM = [[CLLocationManager alloc] init];
LM.delegate = self;
LM.desiredAccuracy = kCLLocationAccuracyBest;
[LM startUpdatingLocation];    
[super viewDidLoad];
}

very simple tutorial on core location. If you're looking to store the data for use later on you'll either want to make a data NSObject class, but seeing as you dont want to make extra classed, define two @property NSStrings lat and long, when the location is created set the two strings to the two variables and you can access them later. The tutorial prints the data on the screen, just leave that part out if you dont want it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM