微信小程序实现天气预报功能(内置自动定位)(源码)

序言

此小程序使用的是最新和风天气API.

样例图

在这里插入图片描述
在这里插入图片描述

和风天气API获取

在这个小程序中我使用的是和风天气的API

  1. 打开官网注册或者登陆你的账号
    在这里插入图片描述
  2. 进入控制台,选择应用管理,新建应用(应用版本 选择 免费开发版,key的类型 选择 Web API)
    在这里插入图片描述
  3. 创建成功后就可以看到要用到的 key了
    在这里插入图片描述

微信小程序后台域名配置

  1. 登陆小程序后台,分别点击开发和开发设置
    在这里插入图片描述
  2. 点击修改,将我们要用到的 API的域名添加到request合法域名里面,https://devapi.qweather.comhttps://geoapi.qweather.com
    在这里插入图片描述

页面代码

.wxml

<view class="header-modular" wx:if="{
    {now}}">
	<image class="bg-wave" src="https://codermoyv.gitee.io/coder-moyv/assets/images/wechat/bg_wave.gif"></image>
	<view class="row">
		<view class="row location-wrap" bindtap="selectLocation">
			<image class="icon" src="/images/icon_location.png"></image>
			<view class="title">{
  {City}} {
  {County}}</view>
		</view>

	</view>
	<view class="row">
		<view class="tmp">{
  {now.temp}}°</view>
		<image class="icon-weather" src="https://codermoyv.gitee.io/coder-moyv/assets/images/wechat/weather_custom/{
    {now.icon}}.png"></image>
	</view>
	<view class="tips-wrap">
		<view class="tips ">{
  {now.windDir}} {
  {now.windScale}}级</view>
		<view class="tips ">湿度 {
  {now.humidity}}%</view>
		<view class="tips ">气压 {
  {now.pressure}}Pa</view>
	</view>
</view>

<view class="card-modular " wx:if="{
    {hourly}}">
	<view class="title">24小时预报</view>
	<view class="card-wrap">
		<block wx:for="{
    {hourly}}" wx:key="index">
			<view class="item hourly">
				<view class="text-gray">{
  {item.time}}</view>
				<image class="icon" src="https://codermoyv.gitee.io/coder-moyv/assets/images/wechat/weather_custom/{
    {item.icon}}.png"></image>
				<view class="text-primary mb-32">{
  {item.temp}}°</view>
				<view>{
  {item.windDir}}</view>
				<view class="text-gray">{
  {item.windScale}}级</view>
			</view>
		</block>
	</view>
</view>

<view
  • 9
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 20
    评论
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值