簡體   English   中英

使用NSNumberFormatter格式化坐標

[英]Formatting coordinate with NSNumberFormatter

我正在嘗試使用NSNumberFormatter格式化CLLocation坐標,以便從數字44.325290獲得類似於此44°32'52.90“ N的內容。

我試圖設置一個數字格式化程序(查看文檔 ),但是不起作用。 我無法指定其他分隔符,例如'和。

碼:

- (NSNumberFormatter *)coordFormatter {
    if (coordFormatter == nil) {
        coordFormatter = [[NSNumberFormatter alloc] init];
        [coordFormatter setPositiveFormat:@"#0.0#####"];
        [coordFormatter setDecimalSeparator:@"°"];
        [coordFormatter setPositiveSuffix:@"\" N"];
    }
return coordFormatter;
}

使用此代碼,我得到的字符串如44°325290“ N

有人可以幫我嗎?

使用NSString替換格式,或擴展自己的格式化程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM