我对 iOS 开发完全陌生,所以我可能做错了,但我有一个类用于获取坐标 gps 数据,我希望将其作为可以在许多应用程序中重用的通用类。我的问题是从 gps 获取数据以正确显示在其他应用程序中。
这是我的 GPS 类的头文件:
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface LocationAwareness : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property(copy) NSString *longitude;
@property(copy) NSString *latitude;
@end
这是实现:
#import "LocationAwareness.h"
@implementation LocationAwareness
@synthesize longitude;
@synthesize latitude;
- (id)init {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// Stops updating location if data has been updated within 10 minutes
if ( abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 600) {
[locationManager stopUpdatingLocation];
float latitudedata = newLocation.coordinate.latitude;
latitude = [NSString stringWithFormat:@"%f", latitudedata];
float logitudedata = newLocation.coordinate.longitude;
longitude = [NSString stringWithFormat:@"%f", logitudedata];
}
}
@end
现在我似乎找不到任何地方告诉我如何在另一个项目中获取纬度或经度属性。我导入了标头,并尝试将 LocationAwareness.latitude 存储到一个我可以使用的变量中,但我存储它的所有内容最终都是空白的。当我开始我的主类并 aloc 初始化一个位置感知对象时,gps 会启动,所以我认为它可以工作,但我似乎对它如何工作以使一切井井有条的了解不够。我已经在互联网上搜索了几个小时。任何人都知道我做错了什么?