داده های آب و هوا در قالب Watch Face

از آنجا که نسخه 2 ، فرمت چهره Watch شامل پشتیبانی از داده های آب و هوا است. این داده ها طیف وسیعی از معیارها و بازه های زمانی را شامل می شود ، از شرایط فعلی گرفته تا پیش بینی های ساعتی و روزانه.

آب و هوا با استفاده از عبارات قابل دسترسی است. به عنوان مثال ، برای نشان دادن شرایط آب و هوایی فعلی در یک عنصر <Text> ، از عبارت مشابه موارد زیر استفاده کنید:

<Text>
  <Font family="SYNC_TO_DEVICE" size="32">
    <Template>Today's weather: %s
        <Parameter expression="[WEATHER.CONDITION_NAME]"/>
    </Template>
  </Font>
</Text>

در دسترس بودن

چهره های تماشا همیشه باید قبل از دسترسی به سایر اعضای [WEATHER.*] ارزش [WEATHER.IS_AVAILABLE] را بررسی کنید:

<Condition>
  <Expressions>
    <Expression name="is_weather_available">[WEATHER.IS_AVAILABLE]</Expression>
  </Expressions>
  <Compare expression="is_weather_available">
    <!-- Weather is available, so show the weather data. -->
  </Compare>
  <Default>
    <!-- Weather isn't available, so show an appropriate message. -->
  </Default>
</Condition>

علاوه بر این ، چهره ساعت باید [WEATHER.IS_ERROR] را بررسی کند ، که نشان دهنده خطایی در بارگیری داده های آب و هوا است.

Note that [WEATHER.IS_AVAILABLE] and [WEATHER.IS_ERROR] can both be true, where the data is stale and attempts to refresh the data failed. In such cases, the available weather can be shown, along with an indicator to show that there was an error in fetching new data.

تازگی داده ها

The timestamp of the available data can be accessed using [WEATHER.LAST_UPDATED] which is a Unix epoch timestamp in milliseconds.

This value can be formatted using the icuText(,) method to obtain a human-readable representation, as demonstrated in the weather sample .

شرایط آب و هوایی

The current conditions are available in [WEATHER.CONDITION] , with a human-readable version in [WEATHER.CONDITION_NAME] .

The values for [WEATHER.CONDITION] can be seen in data sources . به عنوان مثال، 4 نشان دهنده HEAVY_RAIN است.

سایر معیارها

Watch Face Format provides a range of additional metrics, such as [WEATHER.TEMPERATURE] and [WEATHER.UV_INDEX] . For the full details of available metrics, including units and data types, visit the data sources reference page.

پیش بینی های ساعتی و روزانه

You can access forecast conditions for a specific hour or day in the future as follows:

  • [WEATHER.HOURS.1.CONDITION] - the forecast conditions 1 hour from now.
  • [WEATHER.DAYS.2.CONDITION] - the forecast conditions 2 days from now.

Hourly data can be available up to 8 hours ahead, and daily data up to 5 days ahead. However, the watch face should always check for the availability of forecast data. A different range of hours or days might be available at different times, or different devices. For example, to check whether forecast data is available for 1 hour from now, use [WEATHER.HOURS.1.IS_AVAILABLE] .

پیش بینی های روزانه و ساعتی همچنین دارای طیف وسیعی از معیارها مانند [WEATHER.HOURS.<N>.TEMPERATURE] و [WEATHER.DAYS.<N>.CHANCE_OF_PRECIPITATION] . For the full details of available metrics, including units and data types, visit the data sources reference page.

تست با داده های آب و هوا

To obtain weather data, the Wear OS device must be aware of the device location.

برای حفظ انرژی ، ساعت از سنسور GPS پردازنده برای تعیین مکانی برای پیش بینی آب و هوا استفاده نمی کند و در عوض از یک دستگاه دستی متصل یا از شبکه های موجود به مکان متکی است.

To make location data available for testing, do one of the following:

adb unroot
adb shell cmd location set-location-enabled true
adb root
adb shell appops set 0 android:mock_location allow
adb shell cmd location providers add-test-provider gps
adb shell cmd location providers set-test-provider-enabled gps true
adb shell cmd location providers set-test-provider-location gps --location 37.773972,-122.431297

جزئیات بیشتر

For a complete example of accessing and rendering weather data, see the GitHub sample .

{% کلمه به کلمه %} {% آخر کلمه %} {% کلمه به کلمه %} {% آخر کلمه %}