admin 管理员组文章数量: 888398
map组件 markers 展示当前位置修改标记点图标
<view><map id="myMap" show-location class="container" style="width: 100%; height: 800rpx;" />
</view>onShow: function() {this.mapCtx = wx.createMapContext('myMap')this.mapCtx.moveToLocation()
}
改个标记点的默认样式:
方法一
<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})}})}
})
本文标签: map组件 markers 展示当前位置修改标记点图标
版权声明:本文标题:map组件 markers 展示当前位置修改标记点图标 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1699077196h326712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论