实战iPhone GPS定位系统
2010-07-06 05:03:00 来源:WEB开发网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];
- ››iPhone应用帮助残障儿童看图说话
- ››iPhone实用工具AppBox Pro使用教程大揭秘
- ››iphone4省电方法
- ››iphone 获取地址的详细信息
- ››iPhone 库的基本内存管理策略
- ››iPhone加密文字亲手做 私密信息有保障
- ››iphone 根据经纬度坐标取详细地址(包括国,省,市...
- ››iphone/ipad ios cocoa object-c 近期苹果UI部分小...
- ››iphone中如何进行多线程编程
- ››iPhone OS SDK的这些事[安装、下载、版本、实例、...
- ››iPhone ObjectC的NSAutoreleasePool
- ››iPhone 判断设备是在Portrait(纵向)还是(Landscap...
赞助商链接