300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 微信小程序-如何引入地图组件及显示当前所在位置

微信小程序-如何引入地图组件及显示当前所在位置

时间:2023-07-11 11:28:20

相关推荐

微信小程序-如何引入地图组件及显示当前所在位置

 1、代码部分

 wxml

<view class="view"><map id="map" longitude="{{longitude}}" //经度latitude="{{latitude}}" //纬度show-location="true" >//是否显示当前定位</map></view>

 xwss

.view {position: absolute;width: 100%;height: 80%;bottom: 20%;}

 js

data: {//自定义标记点数组markers:[],//纬度latitude:'',//经度longitude:'',},onLoad: function() {var that = this; // 获取当前定位的经纬度信息wx.showLoading({title:"定位中",mask:true})wx.getLocation({type: 'gcj02',altitude:true,//高精度定位//定位成功,更新定位结果success: function (res) {var latitudee = res.latitudevar longitudee = res.longitudethat.setData({longitude:parseFloat(longitudee),latitude: parseFloat(latitudee),})},//定位失败回调fail:function(){wx.showToast({title:"定位失败",icon:"none"})},complete:function(){//隐藏定位中信息进度wx.hideLoading()}})},

 2、在app.json中添加代码,用于授权定位

 3、效果查看

 END

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。