wxml
<map
id="map"
style="width: 100%; height: 300px;"
latitude="{{latitude}}"
longitude="{{longitude}}"
markers="{{markers}}"
covers="{{covers}}"
show-location
></map>
js
// 引用百度地图微信小程序JSAPI模块
var bmap = require('../../utils/bmap-wx.min.js');
Page({
data: {
// 这个值是在百度地图平台api中申请的。
ak: "zd0GVW0Hg3R1kGMSWkOQZXuyo406h0id",
latitude: 23.099994, //纬度
longitude: 113.324520, //经度
address: '', //地址
cityInfo: {}, //城市信息
markers: [{
id: 1,
latitude: 23.099994,
longitude: 113.324520,
name: 'T.I.T 创意园'
}],
covers: [{
latitude: 23.099994,
longitude: 113.344520,
iconPath: '/image/location.png'
}, {
latitude: 23.099994,
longitude: 113.304520,
iconPath: '/image/location.png'
}]
},
onLoad: function (options) {
let that = this
var BMap = new bmap.BMapWX({
ak: that.data.ak
});
// 发起regeocoding检索请求
BMap.regeocoding({
location: that.data.latitude + "," + that.data.longitude,
success: function(res) {
console.log(res)
}
});
}
})