私は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を使用可能な変数に格納しようとしましたが、格納するすべてが空白になります。メインクラスを開始してlocationawarenessオブジェクトをalocinitすると、gpsが起動するので、機能していると思いますが、これがどのように機能してすべてを正常に処理するかについては十分に理解していないようです。私は何時間もインターネットを検索してきました。誰かが私が間違っていることを知っていますか?