// pages/demo/demo.js Page({ /** * 页面的初始数据 */ data: {}, // 引入腾讯地图文件js // var QQMapWX = require('../../libs/qqmap-wx-jssdk.js'), // var qqmapsdk onLoad: function (options) { this.getLocation(); }, getLocation() { var that = this; wx.getLocation({ type: "wgs84", success: function (res) { var locationString = res.latitude + "," + res.longitude; wx.request({ url: "https://apis.map.qq.com/ws/geocoder/v1/", data: { key: "C5KBZ-RISKD-INW4P-PWYQJ-QC6C7-BQBGC", location: locationString }, method: "GET", success: function (res) { console.log("用户位置信息", res.data, that); var district = res.data.result.ad_info.district; var city = res.data.result.ad_info.city console.log(city); console.log(district); that.setData({ city, district }); } }); } }); } });