[英]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? 如何在不创建其他视图控制器或标签控制器的情况下将核心位置数据(纬度,经度,海拔高度)集成到我的(单视图)iPhone应用程序中? 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.
换句话说,当我运行该应用程序时,我希望看到一个空白屏幕(xView),但能够在后台收集(经度,纬度信息),然后可以将坐标存储在文件中或将其传递给其他功能。抱歉,这听起来很愚蠢,我是iOS开发的新手。
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.
如果要存储数据以备后用,则要么要创建一个数据NSObject类,但由于不想进行额外的分类,请在创建位置时定义两个@property NSStrings lat和long。将两个字符串设置为两个变量,以后可以访问它们。 The tutorial prints the data on the screen, just leave that part out if you dont want it
本教程将数据打印在屏幕上,如果您不想要的话,就将其省略
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.