2012-02-12 138 views
0

我在我的iPhone應用程序中使用CoreLocation,這讓我緯度和經度這樣的 - 37.3323°,-122.031°CoreLocation ::獲取經緯度座標

我想刪除度(°)符號的結束。我怎麼做 ?

我目前使用的源代碼 -

NSString *lat = [NSString stringWithFormat:@"%g\u00B0",newLocation.coordinate.latitude]; 
NSString *lon = [NSString stringWithFormat:@"%g\u00B0",newLocation.coordinate.longitude]; 

感謝

+2

那麼,你明確地加上'\ u00B0',這是度號的Unicode編號。把它砍掉,然後使用'@「%g」'你就會很好。 – 2012-02-12 07:13:53

回答

4

我猜您正在使用的CLLocation的描述屬性。如果是這樣,不要;改用座標屬性。它使您可以直接訪問數字,然後您可以根據需要進行格式化。

+0

我正在使用座標屬性。我在問題中添加了源代碼 – 2012-02-12 05:56:19

0

您只需做到以下幾點:

double *lat = newLocation.coordinate.latitude; 
double *lon = newLocation.coordinate.longitude; 

//而NSLog的

NSLog(@"Latitude: %f Longitude: %f", lat, lon); 
3

使用:

NSString *lat = [NSString stringWithFormat:@"%g",newLocation.coordinate.latitude]; 
NSString *lon = [NSString stringWithFormat:@"%g",newLocation.coordinate.longitude]; 

你明確地添加 「度」 通過附加的Unicode學位字符。只需刪除unicode。