【问题标题】:iPhone GPS LocationiPhone GPS 定位
【发布时间】:2009-07-08 05:53:23
【问题描述】:

我想在目标 C 中获取 iPhone 上的经度和纬度。谁能指导我如何以编程方式获取这些坐标?

#import <Foundation/Foundation.h>

@class CLLocationManager;

@interface CLLocationController : NSObject {
    CLLocationManager *locationManager; 
}

@property (nonatomic, retain) CLLocationManager *locationManager; 

@end

当我写上面的代码时,我会看到以下错误

/Hab/Folder/Classes/CLLocationController.m:10:30: error: CLLocationManager.h: No such file or directory
/Hab/Folder/Classes/CLLocationController.m:21: warning: receiver 'CLLocationManager' is a forward class and corresponding @interface may not exist
/Hab/Folder/Classes/CLLocationController.m:22: error: accessing unknown 'delegate' component of a property

【问题讨论】:

  • developer.apple.com 阅读文档

标签: iphone objective-c latitude-longitude


【解决方案1】:

使用 CLLocationManager,将对象设置为委托并开始获取更新。

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
self.locationManager.delegate = self; 
[self.locationManager startUpdatingLocation]; 

然后实现委托:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]); 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]); 
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2017-11-28
    • 2013-03-08
    相关资源
    最近更新 更多