我们在HarmonyOS开发中,如何一个简单的应用内实时天气查询功能?

阅读 543
1 个回答

需要在应用中查询并展示实时天气信息。

使用天气服务API来实现。

参见:https://developer.huawei.com/consumer/cn/doc/

import weatherService from '@ohos.weatherService';

@Entry
@Component
struct WeatherQuery {
  getWeather(city: string) {
    weatherService.getRealtimeWeather(city, (err, weatherData) => {
      if (!err) {
        console.log(`当前${city}天气:${weatherData}`);
      }
    });
  }

  build() {
    Column() {
      Button('查询天气')
        .onClick(() => this.getWeather('北京'));
    }
  }
}

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进