Anda dapat memilih dari METRIC atau IMPERIAL untuk semua endpoint Weather API.
Untuk meminta sistem unit, tetapkan units_system ke METRIC atau IMPERIAL. Jika tidak ada
units_system yang ditentukan, setelan defaultnya adalah METRIC.
https://weather.googleapis.com/v1/currentConditions:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE&units_system=IMPERIAL
Nilai Weather API diubah dari unit METRIK ke IMPERIAL
Tabel berikut mencantumkan nilai respons Weather API yang dapat dikonversi antar-sistem unit.
| Konversi Satuan (Metrik ke Imperial) | Nilai Weather API |
|---|---|
| Celsius (°C) ke Fahrenheit (°F) | Suhu, Suhu yang Dirasakan, Titik Embun, Indeks Panas, Suhu Angin, Suhu Bola Basah |
| Milimeter (mm) ke Inci (in) | Presipitasi, QPF, Ketebalan Es |
| Kilometer/jam (km/j) ke Mil/jam (mph) | Kecepatan Angin, Embusan Angin |
| Kilometer (km) ke Mil (mil) | Visibilitas |
Contoh untuk respons currentConditions
Tabel berikut mencantumkan nilai yang disertakan dalam isi respons permintaan currentConditions. Nilai dalam huruf tebal berwarna biru telah berubah dari METRIC menjadi
IMPERIAL unit:
| Fitur Weather API | METRIC (default) | IMPERIAL |
|---|---|---|
| Waktu Saat Ini | 2025-03-06T11:08:49.126979608Z | 3/6/2025, 6:08:49 AM |
| Zona Waktu | Amerika/New_York | Amerika/New_York |
| Adalah Siang Hari | FALSE | FALSE |
| Deskripsi Cuaca | Sebagian besar berawan | Sebagian besar berawan |
| Suhu | 11,5 °C | 52,7 °F |
| Suhu Terasa Seperti | 9,9 °C | 49,7 °F |
| Titik Embun | 8,7 °C | 47,6 °F |
| Indeks Panas | 11,5 °C | 52,7 °F |
| Angin Dingin | 9,9 °C | 49,7 °F |
| Kelembapan Relatif | 83 % | 83 % |
| Indeks UV | 0 | 0 |
| Kemungkinan Presipitasi | 9 % | 9 % |
| Presipitasi | 0 mm | 0 inci |
| Probabilitas Badai Petir | 0 | 0 |
| Tekanan Udara | 991,47 MB | 991,47 MB |
| Arah Angin | 275 ° | 275 ° |
| Arah Angin (Kardinal) | BARAT | BARAT |
| Kecepatan Angin | 14 km/j | 9 mpj |
| Hembusan Angin | 27 km/j | 17 mpj |
| Visibilitas | 10 km | 6 mil |
| Cloud Cover | 65 % | 65 % |
| Perubahan Suhu | 1,4 °C | 2,6 °F |
| Suhu Maksimal | 13,2 °C | 55,8 °F |
| Suhu Minimum | 10,1 °C | 50,1 °F |
| QPF | 27,5564 mm | 1,0849 inci |
Sistem satuan di dunia
Sistem satuan menurut negara
Sebagian besar negara di luar Amerika Serikat menggunakan sistem METRIC, sedangkan
Amerika Serikat menggunakan sistem IMPERIAL. Beberapa negara, seperti Inggris Raya dan Kanada, menggunakan gabungan kedua sistem tersebut. Untuk peta dan daftar lengkap
negara yang menggunakan sistem metrik, lihat
Metrikasi.

Mengonversi unit dari respons Weather API
Mengonversi unit secara manual
Anda dapat mengonversi unit secara manual menggunakan skrip berikut:
function convert(conversionType, value) { if (value === null || value === undefined || typeof value !== 'number') { return "Invalid input"; // Handle null, undefined, or non-numeric input } switch (conversionType) { case 'C_to_F': // Celsius to Fahrenheit let convertedCtoF = (value * 9 / 5) + 32; return convertedCtoF.toFixed(2) + " °F"; case 'mm_to_in': // Millimeters to Inches let convertedMmToIn = value * 0.0393701; return convertedMmToIn.toFixed(2) + " in"; case 'km_to_mi': // Kilometers to Miles let convertedKmToMi = value * 0.621371; return convertedKmToMi.toFixed(2) + " mi"; case 'km/h_to_mph': // Kilometers per hour to Miles per hour let convertedKmHToMph = value * 0.621371; return convertedKmHToMph.toFixed(2) + " mph"; case 'millibar_to_psi': // Millibar to PSI let convertedMillibarToPsi = value * 0.0145038; return convertedMillibarToPsi.toFixed(2) + " psi"; default: return "Invalid conversion type"; } } console.log(convert('C_to_F', 10)); // Output: 50.00 °F console.log(convert('mm_to_in', 25)); // Output: 0.98 in console.log(convert('invalid_type', 5)); // Output: Invalid conversion type
Mengonversi satuan menggunakan library
Anda juga dapat menggunakan library seperti convert-units untuk mengonversi unit:
// module
import convert from 'convert-units';
// or script inclusion
// <script src="https://unpkg.com/convert@5.8.0/dist/index.js" ></script>
// let convert = convert.convert
function convertWithLibrary(conversionType, value) {
if (value === null || value === undefined || typeof value !== 'number') {
return "Invalid input";
}
try {
switch (conversionType) {
case 'C_to_F':
let convertedCtoF = convert(value, 'C').to('F');
return convertedCtoF.toFixed(2) + " °F";
case 'mm_to_in':
let convertedMmToIn = convert(value, 'mm').to('in');
return convertedMmToIn.toFixed(2) + " in";
case 'km_to_mi':
let convertedKmToMi = convert(value, 'km').to('mi');
return convertedKmToMi.toFixed(2) + " mi";
case 'km/h_to_mph':
// km/h is not directly supported, so we convert km to mi
// then assume it's per hour
let convertedKmToMiValue = convert(value, 'km').to('mi');
return convertedKmToMiValue.toFixed(2) + " mph";
case 'millibar_to_psi':
// millibar is not directly supported, so convert millibar to bar, then bar to psi
let barValue = value / 1000;
let convertedMillibarToPsi = convert(barValue, 'bar').to('psi');
return convertedMillibarToPsi.toFixed(2) + " psi";
default:
return "Invalid conversion type";
}
} catch (error) {
console.error("Conversion error:", error);
return "Conversion failed";
}
}
console.log(convertWithLibrary('C_to_F', 10)); // Output: 50.00 °F
console.log(convertWithLibrary('mm_to_in', 25)); // Output: 0.98 in
console.log(convertWithLibrary('invalid_type', 5)); // Output: Invalid conversion type