1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 微信小程序之地图组件

微信小程序之地图组件

时间:2023-08-12 11:42:27

相关推荐

微信小程序之地图组件

前言:官方提供好了 map组件直接使用即可,具体配置可以参考demo

1、配置权限

"permission": {"scope.userLocation": {"desc": "请求获取地理信息"}}

2、使用map

wx.getLocation() 可以获取当前位置,需要在小程序中申请,也可以使用demo中的方式获取(如下api获取上下文对象,再进行对应功能的获取)

wx.createMapContext

功能描述

//js文件Page({data:{latitude: 23.099994,longitude: 113.324520,markers: [{id: 1,latitude: 23.099994,longitude: 113.324520,name: 'T.I.T 创意园'}],covers: [{latitude: 23.099994,longitude: 113.344520,iconPath: '/image/location.png'}, {latitude: 23.099994,longitude: 113.304520,iconPath: '/image/location.png'}]},onLoad(option) {},onShow() {this.getCurrentPosition()},handlePosition(e){let longitude = e.detail.longitudelet latitude = e.detail.latitude},getCurrentPosition(){wx.getLocation().then(res => {console.log(res);this.setData({longitude: res.longitude,latitude: res.latitude,markers: [{id: 0,height: 50,width: 40,longitude: res.longitude,latitude: res.latitude}]})});wx.onLocationChange(it=>{console.log(it,'--监听位置--')})},//查看视频lookVideo(){wx.redirectTo({url:'../video/index'})}})

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