onLoad: function () { var that = this //定位用户经纬度 wx.getLocation({ type: 'wgs84', success: function (res) { var latitude = res.latitude; var longitude = res.longitude; //根据经纬度去腾讯地图接口获取用户位置 var data = { lat:latitude, lng:longitude } // 定位 wx.request({ url: userCarUtil.host + userCarUtil.getCityByGpsOrIp, data: data, success: function (res) { cityId = res.data.data.city_id var city = res.data.data.city_name that.setData({ cityName: city }) // 获取平台免费代卖数据 // console.log("城市id:"+cityId); wx.request({ url: userCarUtil.host + userCarUtil.getChannelByCityId, data: {city_id:cityId}, success: function (res) { that.setData({ getChannelByCityId: res.data }) } }); } }); } }); }