// 引用百度地图微信小程序JSAPI模块 var bmap = require('../../lib/bmap-wx.js'); var wxMarkerData = []; Page({ data: { markers: [], latitude: 0, longitude: 0, rgcData: {} }, goMap: function () { var self = this wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success(res) { const latitude = self.data.latitude const longitude = self.data.longitude wx.openLocation({ latitude, longitude, scale: 15 }) } }) }, makertap: function (e) { var that = this; var id = e.markerId; that.showSearchInfo(wxMarkerData, id); }, onLoad: function (options) { this.setData({ longitude: parseFloat(options.long), latitude: parseFloat(options.lng) }) var that = this; // 新建百度地图对象 var BMap = new bmap.BMapWX({ ak: 'Zk732rbyjd327q7Zj9EOtRjUn2ED1GWK' }); var fail = function (data) { console.log(data) }; var success = function (data) { wxMarkerData = data.wxMarkerData; wxMarkerData[0].longitude = that.data.longitude wxMarkerData[0].latitude = that.data.latitude that.setData({ markers: wxMarkerData }); that.setData({ latitude: wxMarkerData[0].latitude }); that.setData({ longitude: wxMarkerData[0].longitude }); } // 发起regeocoding检索请求 BMap.regeocoding({ fail: fail, success: success, iconPath: '../../images/marker_red.png', iconTapPath: '../../images/marker_red.png' }); } })