地图
map组件的基本使用
<map longitude="113.324520" latitude="23.099994" scale="11"></map>
<button bindtap='handleShow'>显示当前位置</button>
<button type='primary' bindtap='handleOpen'>打开地图选择位置</button>
通过小程序API操作地图
- 获取当前位置坐标(经纬度)wx.getLocation
- 打开地图中的位置 wx.openLocation
- 选中地图的位置并获取位置的详细信息 wx.chooseLocation
handleOpen () {
wx.chooseLocation({
success: function(res) {
console.log(res)
}
})
},
handleShow () {
wx.getLocation({
type: 'gcj02',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
wx.openLocation({
latitude,
longitude,
scale: 18
})
}
})
},