Metric information from the locale

Discussion in 'iPhone/iPad Programming' started by dgdosen, Jul 16, 2008.

  1. macrumors 65816

    dgdosen

    Joined:
    Dec 13, 2003
    Location:
    Seattle
    #1
    I'm trying to extract the measurement system from the locale on the iPhone with kCFLocaleMeasurementSystem or kCFLocaleUsesMetricSystem. They keep coming back to me as non-metric, even though I've rebooted the phone into UK/English.

    Does anyone know if these constants are working? Or maybe how to use them :rolleyes:
     
  2. thread starter macrumors 65816

    dgdosen

    Joined:
    Dec 13, 2003
    Location:
    Seattle
    #2
    Nevermind...

    RTFM! I didn't see you needed to use CFLocaleGetValue to get at those constants. Very cool... You can even play with it in the simulator.

    Code:
    	CFLocaleRef currentLocale;
    	CFBooleanRef usesMetric;
    	NSString *measurement = [[NSString alloc] init];
    	currentLocale = CFLocaleCopyCurrent();
    	usesMetric = CFLocaleGetValue(currentLocale, kCFLocaleUsesMetricSystem);
    
    	if (usesMetric == kCFBooleanFalse)
    	{
    		measurement = @"Miles";
    	}
    	else
    	{	
    		measurement = @"Kilimoters";
    		
    	}
    
     
  3. macrumors member

    Joined:
    May 24, 2003
    #3
    I didn't know you could do that.

    But I should point out that here in the UK, although we use the metric system for pretty much everything else, we still use miles, so it might be better to allow the user to set the units using a preference option.

    Just a thought....
     

Share This Page