本小程序仿摩拜单车的地图显示和拖动部分,单车数据采用周边厕所模拟。index.wxml如下:

  1. <map id="map" bindcontroltap="bindcontroltap" bindregionchange="bindregionchange"

    longitude="{{jd}}" latitude="{{wd}}" markers="{{markers}}" controls="{{controls}}"

    style="width: 100%; height: {{height}}px;"  scale="16"   show-location>

  2. </map>

拖动地图,视野变化设置bindregionchange

页面加载时设置地图高度,control标注,头部广告及注册登录、返回当

前位置、优惠券、充值等。

  1. wx.getSystemInfo({

  2.      success: function (res) {

  3.        maph = res.windowHeight

  4.        mapw = res.windowWidth

  5.        that.setData({

  6.          height: maph,

  7.          controls: [

  8.            {

  9.              id: 1,

  10.              iconPath: '../libs/banner.jpg',

  11.              position: {

  12.                left: 10,

  13.                top: 10,

  14.                width: 390,

  15.                height: 80

  16.              },

  17.              clickable: true

  18.            },

  19.            {

  20.              id: 2,

  21.              iconPath: '../libs/gps.jpg',

  22.              position: {

  23.                left: 10,

  24.                top: maph - 50,

  25.                width: 40,

  26.                height: 40

  27.              },

  28.              clickable: true

  29.            },

  30.            {

  31.              id: 3,

  32.              iconPath: '../libs/log.jpg',

  33.              position: {

  34.                left: mapw / 2 - 80,

  35.                top: maph - 50,

  36.                width: 150,

  37.                height: 40

  38.              },

  39.              clickable: true

  40.            },

  41.            {

  42.              id: 4,

  43.              iconPath: '../libs/gift.jpg',

  44.              position: {

  45.                left: mapw - 60,

  46.                top: maph - 120,

  47.                width: 40,

  48.                height: 40

  49.              },

  50.              clickable: true

  51.            },

  52.            {

  53.              id: 5,

  54.              iconPath: '../libs/cost.jpg',

  55.              position: {

  56.                left: mapw - 60,

  57.                top: maph - 50,

  58.                width: 40,

  59.                height: 40

  60.              },

  61.              clickable: true

  62.            }

  63.          ]

  64.        })

由于需要频繁更新地图中心单车数据,对更新标记进行封装为getbike

  1. function getbike (){

  2.  console.log(mapcenter)

  3.  qqmapsdk.search({

  4.    location: {

  5.      latitude: mapcenter[0],

  6.      longitude: mapcenter[1]

  7.    },

  8.    keyword: '厕所',

  9.    success: function (res) {

  10.      var mark = []      

  11.      var getdata = res.data

  12.      for (var i = 0; i < getdata.length; i++) {

  13.        mark[i] = {

  14.          iconPath: "../libs/mobi.jpg",

  15.          id: i,

  16.          latitude: getdata[i].location.lat,

  17.          longitude: getdata[i].location.lng

  18.        }

  19.        mark.push({

  20.          iconPath: "../libs/c.png",

  21.          id: 99,

  22.          latitude: mapcenter[0],

  23.          longitude: mapcenter[1]

  24.        })

  25.      }

  26.      that.setData({

  27.        markers: mark

  28.      })

  29.    }

  30.  });

  31. }

页面初次加载,获取当前gps位置周围的单车数据

  1. onReady: function () {

  2.    var _this=this

  3.    wx.getLocation({

  4.      type: 'gcj02',

  5.      success: function (res) {

  6.        latitude1 = res.latitude

  7.        longitude1 = res.longitude

  8.        mapcenter = [latitude1, longitude1]

  9.        getbike()

  10.            _this.setData({

  11.              wd: latitude1,

  12.              jd: longitude1,

  13.            })

  14.        }

  15.    })

  16.  },

拖动地图时,先获取地图中心坐标,然后再调用getbike。

  1. //获取中心点

  2.  bindregionchange: function (e) {

  3.    this.mapCtx.getCenterLocation({

  4.      success: function (res) {

  5.        mapcenter = [res.latitude, res.longitude]

  6.      }

  7.    })

  8.    console.log(mapcenter)

  9.         getbike()

  10.  }

    ,

点击控件,根据控件id不同进行处理

  1. //控件

  2.  bindcontroltap: function (e){

  3. console.log(e.controlId)

  4.   var id=e.controlId

  5.   if (id==2){

  6.     this.mapCtx.moveToLocation()

  7.     mapcenter = [latitude1, longitude1]

  8.     getbike()

  9.   }

  10.   else if(id==1){

  11.     wx.navigateTo({

  12.       url: '../free30/free30'

  13.     })

  14.   }

  15.   else if (id==3) {

  16.     wx.navigateTo({

  17.       url: '../log/log'

  18.     })

  19.   }

  20.  }

  21. })

效果图如下:

微信小程序仿摩拜单车相关推荐

  1. android 仿ofo页面,微信小程序_模仿共享单车ofo源代码

    [实例简介] 功能:登陆 定位及地图查看 轮播图广告 我的行程及列表 我的钱包及查看交易明细 [实例截图] [核心代码] 模仿共享单车ofo(微信小程序源代码) └── 模仿共享单车ofo(微信小程序 ...

  2. Android百度地图实例详解之仿摩拜单车APP(包括附近车辆、规划路径、行驶距离、行驶轨迹记录,导航等)

    Android百度地图实例详解之仿摩拜单车APP(包括附近车辆.规划路径.行驶距离.行驶轨迹记录,导航等) 标签: android百度地图行驶轨迹记录共享单车行驶距离和时间 2017-03-08 20 ...

  3. 仿摩拜单车APP(包括附近车辆、规划路径、行驶距离、行驶轨迹记录,导航等)

    本文是由奇虎360公司高磊关于使用百度地图仿摩拜单车APP,原文地址:http://blog.csdn.net/gaolei1201/article/details/60876811 最近共享单车很火 ...

  4. 微信小程序仿微信SlideView组件slide-view

    微信小程序仿微信SlideView组件. 使用 1.安装 slide-view 从小程序基础库版本 2.2.1 或以上.及开发者工具 1.02.1808300 或以上开始,小程序支持使用 npm 安装 ...

  5. Java微信运动步数排序设计_微信小程序仿微信运动步数排行(交互)

    本文介绍了微信小程序仿微信运动步数排行(交互),分享给大家,也给自己留个笔记,废话不多说了,具体如下: 效果图如下: wxml: {{item.name}} {{item.steps}} wxss: ...

  6. android微信运动页面开发,微信小程序仿微信运动步数排行(交互)

    微信小程序仿微信运动步数排行(交互) 发布时间:2020-08-20 00:51:02 来源:脚本之家 阅读:101 作者:祈澈姑娘 本文介绍了微信小程序仿微信运动步数排行(交互),分享给大家,也给自 ...

  7. 微信小程序仿网易云音乐(使用云开发,提供源码)

    微信小程序仿网易云音乐(使用云开发,提供源码)!!!!!!!!!!! 源码: 链接:https://pan.baidu.com/s/1z_ZnRVbT4vjEENimi8yBQQ 提取码:u0o3 一 ...

  8. 微信小程序-仿朋友圈点赞评论操作面板

    目录 微信小程序-仿朋友圈点赞评论操作面板 一.效果 二.实现 1.wxml实现 2.js实现 3.wxss实现 三.记录 1.dataset使用 微信小程序-仿朋友圈点赞评论操作面板 一.效果 二. ...

  9. 到家服务公司php源码,微信小程序-仿五洲到家商城源码

    微信小程序-仿五洲到家商城源码 微信小程序仿五洲到家商城源码是一款精仿五洲到家app界面的小程序源码,适用于各类小程序商城系统,功能及模块均值得借鉴! 对应功能模块 > * 首页(定位成功情况且 ...

最新文章

  1. nacos持久化配置MySQL8_Nacos 数据持久化 mysql8.0
  2. 父类和子类在同一张表
  3. 数据结构为什么那么难?
  4. spring 面向接口编程_Spring面向方面的编程
  5. 使用Nagios打造专业的业务状态监控
  6. 使用iframe设置frameset的高度
  7. ubuntu16.04安装python.h_ubuntu16.04安装python3.6踩过的坑
  8. 关于团队项目的一些思考和理解
  9. 普元eos如何在日志文件中打印SQL语句及参数
  10. MessAPI V1.1.1 QQ音乐、网易云音乐、酷狗音乐、咪咕音乐、酷我音乐、百度音乐API接口
  11. 故障报修管理系统有什么作用?
  12. 高等数学(Calculus I)
  13. 达梦数据库关闭 消息校验的警告 Failure occurs in data_recv_inet_once
  14. echarts的xAxis的type=’time’
  15. 野火iMX6ULL Pro开发板移植SDL2
  16. Mac 下显示隐藏文件或文件夹
  17. python函数内嵌,嵌套函数
  18. 操作符重载and模板(泛化, 全特化, 偏特化)
  19. 利用PsTools删除注册表信息与利用devcon工具禁用设备
  20. [ROM 制作/修改 教程] HTC One X免金卡卡刷官方RUU固件教程【S-ON/OFF通用】

热门文章

  1. 能力培养——学习的10种好方法
  2. 【2022年Spring全家桶】学习路线图和资料整理
  3. 山东新华书店招聘计算机岗位试题,2020山东新华书店招聘考试都考什么
  4. 成功解决Your CPU supports instructions that this TensorFlow binary was not compiled to use AVX AVX2
  5. html 颜色镂空,【前端】canvas应该怎么做镂空(透明色)文字呢?
  6. canvas 动态镂空
  7. 打印机安全研究(二):打印机攻击测试方法和利用工具
  8. URL如何转换成pdf?
  9. TIM 默认存储文件夹修改不成功
  10. 智媒ai文章一键伪原创插件在线生成