实训第七天:天气预报小程序实现自动定位和布局完善

本文介绍了如何在微信小程序中实现自动定位功能,通过腾讯地图API获取经纬度并解析出地址,结合天气API展示实时天气。同时,展示了两种天气预报页面布局方案:滚动布局和表格布局,并提供了相关代码示例。
摘要由CSDN通过智能技术生成

实现自动定位:接入腾讯地图的api,并申请一个key
获取位置接口和经纬度,用位置服务逆解析出ip地址,再将ip地址传值到获取实况天气的接口
代码:
 // wx获取位置接口
    wx.getLocation({
     success: function (res) {
     // 获取到经纬度
    console.log(res);
      // 逆地址解析
          qqmapsdk.reverseGeocoder({
          location:{
            latitude: res.latitude,
            longitude: res.longitude
          },
          success:function(res){
            console.log(res.result.address_component.district.substr(0,2));
            _this.weathertoday(res.result.address_component.district.substr(0, 2));
            _this.weatherweekday(res.result.address_component.district.substr(0, 2));
            }
        })
      }
    });
  },

// 天气api实况天气
  weatherweekday: function (city) {
    var _this = this;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值