views:

221

answers:

4

Hi,

In my app I've got a certain distance in meters.

And I want to display it in kilometers if user prefers kilometers and display it in miles if user prefers miles. And in the first case I want to add to a string "kilometers" at the end and in the second one to add "miles".

What is the best way to achieve this goal?

Thanks.

+2  A: 

Why not make it a user preference?

ceejayoz
Agreed. While kilometers are what we use here in Canada, many older people who are used to the imperial measurement system still think in miles.
Soviut
Definitely user preference. If I ever traveled to Europe, for instance, I'd still be thinking in miles. (Or vice versa for someone traveling to the states and thinking in kilometers etc.).
+3  A: 

Read this article about iPhone locale.

Elzo Valugi
A: 

Unless the iPhone provides this information directly, you'll have to have a lookup table from locale to default unit. Then you should allow the user to override that default.

Draemon
A: 

You could ask the user whether they prefer miles or kilometers, in a preference or something. Then whenever you display a distance you would say.

In pseudo c code

function distance(meters) {
    if (userPrefersKM) {
        return meters / 1000 + " kilometers";
    else if (userPrefersMiles) {
        return meters / METERS_IN_A_MILE + " miles";
}

Where METERS_IN_A_MILE would be about 1600, but you should look that up.

Mike Cooper