// activity/map/map.js const App = getApp() var QQMapWX = require('../../utils/qqmap-wx-jssdk.js'); const { timestampToTime } = require('../../utils/util.js'); var map; map = new QQMapWX({ key: 'RA3BZ-PSGW4-GZUUX-DDAU7-6B54E-KJFQ7' // 必填 }); Page({ /** * 页面的初始数据 */ data: { lat: '', lng: '', markers: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ lng: options.lng, lat: options.lat }) // this.getCoord() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, // 获取经纬度 getCoord() { wx.getLocation({ type: 'gcj02', success: (res) => { const latitude = res.latitude const longitude = res.longitude this.setData({ lng: Number(longitude), lat: Number(latitude) }) }, fail: (e) => {} }) }, selectAddress(e) { var pages = getCurrentPages(); var currPage = pages[pages.length - 1]; //当前页面 var prevPage = pages[pages.length - 2]; //上一个页面 prevPage.setData({ address: e, coordinate: this.data.lng + ',' + this.data.lat }) wx.navigateBack() }, mapTap(e) { wx.showLoading({ title: '获取位置中...', }) let lat = e.detail.latitude let lng = e.detail.longitude let obj = { latitude: lat, longitude: lng, width: 17, height: 24 } this.data.markers.push(obj) this.setData({ markers: this.data.markers }) App._get('store/getDetailsAddress', { lon: lng, lat: lat }, res => { console.log(res, 111) if (res.code === 0) { wx.hideLoading() this.selectAddress(res.data.street_number) } }) // this.pointToAddress(lat, lng, res => { // console.log(res, 11111111) // }) }, bindmarkertap(e) { console.log(e, 222) }, bindpoitap(e) { console.log(e, 222) }, bindlabeltap(e) { console.log(e, 333) }, // 定义 pointToAddress 方法 pointToAddress: function (latitude, longitude, callback) { var _this = this; // 调用接口 map.reverseGeocoder({ location: { latitude: latitude, longitude: longitude }, success: function (res) { // 解析成功返回地址 callback(res.result.ad_info); }, fail: function (res) { console.log(res); }, complete: function (res) {} }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })