环境搭建
注册,获取APPID(没有这个不能真鸡调试)
下载微信web开发者工具(挺多bug,将就用)
打开微信web开发者工具,扫码登录,新建小程序,输入APPID,勾选创建quick start项目。
工程结构
可以看到工程根目录中有个app.js,这里可以定义全局变量,通过getApp()获取。
项目中有了一些示例,已经有了获取用户信息的方法等。
开发地图定位,选择位置功能
我们直接修改index页面来做这个功能。
准备
新建imgs目录,加入2个图标(ic_location和ic_position),用于标记当前位置,和地图中央位置。
添加定位功能
修改app.js,加入定位功能,获取当前位置。
//app.js App({ onLaunch: function () { //调用API从本地缓存中获取数据 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) } ,getUserInfo:function(cb){ var that = this if(this.globalData.userInfo){ typeof cb == "function" && cb(this.globalData.userInfo) }else{ //调用登录接口 wx.login({ success: function () { wx.getUserInfo({ success: function (res) { that.globalData.userInfo = res.userInfo typeof cb == "function" && cb(that.globalData.userInfo) } }) } }) } } //get locationInfo ,getLocationInfo: function(cb){ var that = this; if(this.globalData.locationInfo){ cb(this.globalData.locationInfo) }else{ wx.getLocation({ type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function(res){ that.globalData.locationInfo = res; cb(that.globalData.locationInfo) }, fail: function() { // fail }, complete: function() { // complete } }) } } ,globalData:{ userInfo:null ,locationInfo: null } })
地图控件布局
修改pages/index/index.wxml文件,添加map标签,如下
<map id="map4select" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" scale="20" style="width:{{map_width}}px;height:{{map_height}}px" bindregionchange="regionchange" controls="{{controls}}"> </map>
需要给地图指定一个id,后面可以通过id获取地图的上下文。
监听bindregionchange事件,地图变化的时候可以监听到。
地图的大小不要写死,动态设置,我这里打算设置为宽高都是屏幕宽度。
controls是固定在map组件上面的。一开始我想用image替代,但是设置z-index也不能在地图上面,毕竟不是H5开发。
逻辑代码编写
编辑index.js
var app = getApp() Page({ data:{ map_width: 380 ,map_height: 380 } //show current position ,onLoad: function(){ var that = this; // 获取定位,并把位置标示出来 app.getLocationInfo(function(locationInfo){ console.log('map',locationInfo); that.setData({ longitude: locationInfo.longitude ,latitude: locationInfo.latitude ,markers:[ { id: 0 ,iconPath: "../../imgs/ic_position.png" ,longitude: locationInfo.longitude ,latitude: locationInfo.latitude ,width: 30 ,height: 30 } ] }) }) //set the width and height // 动态设置map的宽和高 wx.getSystemInfo({ success: function(res) { console.log('getSystemInfo'); console.log(res.windowWidth); that.setData({ map_width: res.windowWidth ,map_height: res.windowWidth ,controls: [{ id: 1, iconPath: '../../imgs/ic_location.png', position: { left: res.windowWidth/2 - 8, top: res.windowWidth/2 - 16, width: 30, height: 30 }, clickable: true }] }) } }) } //获取中间点的经纬度,并mark出来 ,getLngLat: function(){ var that = this; this.mapCtx = wx.createMapContext("map4select"); this.mapCtx.getCenterLocation({ success: function(res){ that.setData({ longitude: res.longitude ,latitude: res.latitude ,markers:[ { id: 0 ,iconPath: "../../imgs/ic_position.png" ,longitude: res.longitude ,latitude: res.latitude ,width: 30 ,height: 30 } ] }) } }) } ,regionchange(e) { // 地图发生变化的时候,获取中间点,也就是用户选择的位置 if(e.type == 'end'){ this.getLngLat() } } ,markertap(e) { console.log(e) } })
展示
这样,就OK啦,用户可以看到自己的定位,如果觉得有偏差,可以移动地图,把中央点放到自己认为的准确位置上。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]