简体   繁体   English

如何在不引入View或Tab控制器的情况下将核心位置数据集成到我的空白iPhone App中?

[英]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.

相关问题 推出iPhone应用程序时如何保存初始数据? - how can I hold initial data when introducing an iPhone app? 在iPhone应用程序中启动应用程序时如何检索输入的选项卡栏视图控制器中输入的用户输入数据 - How to retrieve user input data entered tab bar View Controller when application start in iphone app 如何在iPhone的View Controller中的TableView中重新加载数据 - How can I reload data in tableview in view controller in iphone 如何防止视图覆盖基于标签的应用程序中的标签控制器? - How can I prevent a view from covering my tab controller in my tab based application? iphone标签栏控制器和核心数据 - iphone tab bar controller and core data 如何在iPhone应用程序中为此自定义视图转换设置动画? - How can I animate this custom view transition in my iPhone app? 如何在iPhone应用程序中使用2选择器视图? - How can i use 2 picker view in my iPhone app? 如何向我的 iphone 应用程序添加额外的“视图”? - How can I add an additional "view" to my iphone app? 如何在iPhone上为控制器分配视图? - How can I assign a view to a controller on iPhone? 如何创建一个新的基于最小笔尖的iPhone应用程序,并将标签栏控制器的视图作为根视图? - How do I create a new minimal nib based iPhone app with a tab bar controller's view as the root view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM