2013-07-06 50 views
0

我有一個單身人士,產生長,lats。我可以登錄他們,但希望能夠得到他們。我究竟做錯了什麼?從單身人士獲取字符串

singleton.h

@interface ClassLocationManager : NSObject <CLLocationManagerDelegate> { 

    NSString *lat; 
    NSString *longt; 
} 

@property (nonatomic, strong) CLLocationManager* locationManager; 
@property (nonatomic, retain) NSString *lat; 
@property (nonatomic, retain) NSString *longt; 

+ (ClassLocationManager*) sharedSingleton; 

singleton.m - 在所述longt,經緯度串給定的值 - (ID)初始化

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    int degrees = newLocation.coordinate.latitude; 
    double decimal = fabs(newLocation.coordinate.latitude - degrees); 
    int minutes = decimal * 60; 
    double seconds = decimal * 3600 - minutes * 60; 
    lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds]; 
    NSLog(@" Current Latitude : %@",lat); 

    degrees = newLocation.coordinate.longitude; 
    decimal = fabs(newLocation.coordinate.longitude - degrees); 
    minutes = decimal * 60; 
    seconds = decimal * 3600 - minutes * 60; 
    longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds]; 
    NSLog(@" Current Longitude : %@",longt); 
    [manager stopUpdatingLocation]; 

} 

codethatcallsthem.m

NSString *formatted3 = [[ClassLocationManager sharedSingleton] longt]; 
NSString *formatted4 = [[ClassLocationManager sharedSingleton] lat]; 

非常感謝。

回答

2

你的屬性不匹配您的伊娃名字..

  1. 要麼離開實例變量並使用自動創建的那些(_longt,_lat)

  2. 或更好,但說self.longt =和self.lat =

  3. 或壞的:使用@合成,使性能使用現有的高德

- 我會用2.

+0

選項2返回在(id)init中設置的值,但不返回(void)locationManager中生成的值。 –

+0

lat = [NSString stringWithFormat:@「%d°%d'%1.4f \」「,degrees,minutes,seconds]; => self.lat = ... longt相同 –

+0

這就是我所做的 - 這是一個時間問題 - 我需要解決如何延遲這個過程,直到它有結果 - 非常感謝。 –