首先wxml引入map组件
<!-- map.wxml -->
讯享网
<map id="map" longitude="113." latitude="23.099994" scale="14" controls="{ {controls}}" bindcontroltap="controltap" markers="{ {markers}}" bindmarkertap="markertap" polyline="{ {polyline}}" bindregiοnchange="regionchange" show-location style="width: 100%; height: 300px;"></map>
map组件中增加:show-location属性后,访问地图就显示显示带有方向的当前定位点
也可以做成事件:
讯享网 currentLoaction:function(e){//地图上显示图标 wx.getSystemInfo({ success: function (res) { widthCtr = res.screenWidth; //console.log(widthCtr + "====="); e.setData({ height: res.windowHeight - 59, controls: [ { id: 1, iconPath: '../images/1.png', position: { left: res.screenWidth - 50, top: 300 - 50, width: 30, height: 30 }, clickable: true } ] }) } }) }
触发定位当前事件
controltap(e) { var that = this; wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: function (res) { var latitude = res.latitude var longitude = res.longitude that.setData({ latitude: latitude,//纬度 longitude: longitude,//经度 }) } }) }
扫描二维码看效果

点击下载:源码地址

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/111767.html