微信小程序map组件之移动map选取位置,效果图如下:
微信小程序map组件,实现拖拽定位,获取定位位置,点击cover-image回到定位原点
手机效果相同。
废话不多说,上代码
wxml代码:
<view class="container">
<map id="map4select" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" controls="{{controls}}" markers="{{markers}}" show-location bindcontroltap="controltap" polyline="{{polyline}}" bindmarkertap="markertap" circles="{{circles}}" bindregionchange="regionchange" >
<cover-image class="cover-image" bindtap="my_location" src="/imgs/my_location.png" />
<cover-image class="cover-image_confirm" bindtap="confirm_bag" src="/imgs/confirm.png" />
</map>
</view>
regionchange(e) {
console.log(e)
// 地图发生变化的时候,获取中间点,也就是用户选择的位置toFixed
if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
console.log(e)
var that = this;
this.mapCtx = wx.createMapContext("map4select");
this.mapCtx.getCenterLocation({
type: 'gcj02',
success: function(res) {
console.log(res)
that.setData({
latitude: res.latitude,
longitude: res.longitude,
circles: [{
latitude: res.latitude,
longitude: res.longitude,
color: '#FF0000DD',
fillColor: '#d1edff88',
radius: 3000,//定位点半径
strokeWidth: 1
}]
})
}
})
}
},
//定位到自己的位置事件
my_location: function(e) {
var that = this;
that.onLoad();
},
可实现拖拽地图获取定位点的经度纬度以及地理位置等操作
详细代码QQ:961052877
版权声明:本文为u010481239原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。