Search code examples
javascriptapigeolocationunits-of-measurement

Find metric "Speed, Degree, etc..." standard by location


I have a program that displays the Weather in the current region of the users' computer.

The problem is that I want to automate the metrics conversion.

so for example in Europe, we measure the heat with Celsius and in the USA we measure it with Fahrenheit same goes for Km/H and M/H in speed respectively.

I want to know if there is a way to know the metric system of a country without having to write a hardcoded table for every country in the world.


Solution

  • Some operating systems expose an API to find the preferred measurement standard.

    Otherwise, if you know their location, you can default to Imperial in the United States, Liberia or Myanmar and use Metric in other locations:

    The Imperial system is used in the United States, Liberia and Myanmar

    Regardless, you should still allow users to manually choose their preference.