wxml:
<map longitude="{{marks[0].longitude}}" latitude="{{marks[0].latitude}}" scale="16" markers="{{marks}}" ></map>
<button type="primary" bindtap="chooseLocation">选择位置</button>
wxss:
map{
width: 100%;
height: 450rpx;
}
button{
margin: 50rpx;
}
js:
Page({
data: {
marks:[
{
latitude:39.9087,
longitude:116.3975,
title:"",
iconPath:"../../images/position1.png",
width:30,
height:30
}
]
},
chooseLocation: function(){
var that = this
wx.chooseLocation({
success: function(res){
console.log(res)
that.setData({
marks:[
{
latitude:res.latitude,
longitude:res.longitude,
title:"我的位置",
iconPath:"../../images/position1.png",
width:30,
height:30
},
]
})
},
})
},
onLoad: function (options) {
}
})
前端效果图:
选择位置前:
选择位置时:
选择位置后:
后端运行结果: