WEB开发网
开发学院手机开发iPhone 开发 实战iPhone GPS定位系统 阅读

实战iPhone GPS定位系统

 2010-07-06 05:03:00 来源:WEB开发网   
核心提示:IBOutlet UITextField *longitudeTextField;IBOutlet UITextField *accuracyTextField;CLLocationManager *lm;}@property (retain, nonatomic) UITextField *latitudeTextF

IBOutlet UITextField *longitudeTextField;

IBOutlet UITextField *accuracyTextField;

CLLocationManager *lm;

}

@property (retain, nonatomic) UITextField *latitudeTextField;

@property (retain, nonatomic) UITextField *longitudeTextField;

@property (retain, nonatomic) UITextField *accuracyTextField;

@end

若要使用CLLocationManager类,需要在你的视图控制器类中实现CLLocationManagerDelegate协议,还需要创建三个出口用于连接视图窗口中的三个TextFiled视图。

回到界面编辑器,单击并拖动文档的所有者项目到三个TextField视图,然后分别选择latitudeTextField,longitudeTextField和accuracyTextField。

在 LBSViewController.m文件中查询以下代码中的粗体部分:

#import "LBSViewController.h"

@implementation LBSViewController

@synthesize latitudeTextField, longitudeTextField, accuracyTextField;

- (void) viewDidLoad {

lm = [[CLLocationManager alloc] init];

if ([lm locationServicesEnabled]) {

lm.delegate = self;

lm.desiredAccuracy = kCLLocationAccuracyBest;

lm.distanceFilter = 1000.0f;

[lm startUpdatingLocation];

}

}

- (void) locationManager: (CLLocationManager *) manager

didUpdateToLocation: (CLLocation *) newLocation

fromLocation: (CLLocation *) oldLocation{

NSString *lat = [[NSString alloc] initWithFormat:@"%g",

newLocation.coordinate.latitude];

latitudeTextField.text = lat;

NSString *lng = [[NSString alloc] initWithFormat:@"%g",

newLocation.coordinate.longitude];

longitudeTextField.text = lng;

NSString *acc = [[NSString alloc] initWithFormat:@"%g",

newLocation.horizontalAccuracy];

accuracyTextField.text = acc;

[acc release];

[lat release];

[lng release];

上一页  1 2 3 4 5 6  下一页

Tags:实战 iPhone GPS

编辑录入:coldstar [复制链接] [打 印]
赞助商链接