當(dāng)前位置展示:
<view>
<map id="myMap" show-location class="container" style="width: 100%; height: 800rpx;" />
</view>
onShow: function() {
this.mapCtx = wx.createMapContext('myMap')
this.mapCtx.moveToLocation()
}
改個標(biāo)記點的默認樣式:
方法一
<view>
<map id="myMap" scale="16" markers="{{markers}}" bindmarkertap="markertap" bindregionchange="regionchange" show-location style="width: 100%; height: 400px;"></map>
</view>
Page({
data: {
markers: [{
iconPath: "../../static/images/home/icon.png",
longitude:121.45088,
latitude:31.25145,
id: 0,
width: 34,
height: 49
}]
},
regionchange(e) {
console.log(e)
},
markertap(e) {
console.log(e)
},
onShow: function () {
this.mapCtx = wx.createMapContext('myMap')
this.mapCtx.moveToLocation()
const lat= "markers[0].latitude";
const log= "markers[0].longitude";
var that = this;
wx.getLocation({
type: "wgs84",
success: function(res){
that.setData({
[lat]:res.latitude,
[log]:res.longitude
})
}
})
}
})
方法二
<view>
<map id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="16" markers="{{markers}}" bindmarkertap="markertap" bindregionchange="regionchange" show-location style="width: 100%; height: 400px;"></map>
</view>
Page({
data: {
longitude:121.45088,
latitude:31.25145,
markers: [{
iconPath: "../../static/images/home/icon.png",
longitude:121.45088,
latitude:31.25145,
id: 0,
width: 34,
height: 49
}]
},
regionchange(e) {
console.log(e)
},
markertap(e) {
console.log(e)
},
onShow: function () {
const lat= "markers[0].latitude";
const log= "markers[0].longitude";
var that = this;
wx.getLocation({
type: "wgs84",
success: function(res){
that.setData({
latitude: res.latitude,
longitude: res.longitude,
[lat]:res.latitude,
[log]:res.longitude
})
}
})
}
})
?
本文摘自 :https://blog.51cto.com/u