2011-08-01 95 views
5

我想知道如何將CLLocationCoordinate2D的緯度和經度值轉換爲數字或字符串值。 艾弗嘗試了幾種不同的方法,但他們arene't工作:將CLLocationCoordinate2D類型轉換爲數字或字符串

CLLocationCoordinate2D centerCoord; 
centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ; 
centerCoord.longitude = self.locModel.userLocation.coordinate.longitude; 
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", centerCoord.latitude]; 
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", centerCoord.longitude]; 

NSLog("User's latitude is: %@", tmpLat); 
NSLog("User's longitude is: %@", tmpLong); 

這將返回由編譯器警告。

的警告

warning: passing argument 1 of 'NSLog' from incompatible pointer type 

我該怎麼辦呢?

任何幫助,將不勝感激。

感謝

回答

7

您沒有提到的警告是什麼,但它很可能是因爲您在NSLog的字符串的前面忘了@

NSLog(@"User's latitude is: %f", self.locModel.userLocation.coordinate.latitude); 
NSLog(@"User's longitude is: %f", self.locModel.userLocation.coordinate.longitude); 

你更新的代碼應該是:

NSLog(@"User's latitude is: %@", tmpLat); 
NSLog(@"User's longitude is: %@", tmpLong); 

NSLog需要一個NSString參數,前面需要一個@符號。沒有@符號,該字符串是一個普通的C字符串,而不是NSString對象。

+0

對不起,安娜卡列尼娜,關於混亂。我更新了我的問題信息並添加了警告。請參閱上面的 謝謝 – banditKing

+1

問題的確是你沒有在NSLog字符串前面的@符號。 – Anna