效果图:

思路:

1、首先获取一系列的坐标点,然后将这些坐标从头到尾链接起来。(参考微信小程序地图组件polyline属性

2、在获取的坐标点上标注某一个位置,实现打点。(参考微信小程序地图组件marker属性 )

3、使用map组件

微信小程序地图组件api地址:https://developers.weixin.qq.com/miniprogram/dev/component/map.html

下面直接展示代码:

wxml:

<view class="page-section page-section-gap"><!-- longitude="{{longitude}}" latitude="{{latitude}}" scale="16" height: {{view.Height}}px;show-location--><map class="navi_map"  include-points='{{points}}' longitude="{{longitude}}" latitude="{{latitude}}" polyline="{{polyline}}" markers="{{markers}}" bindcallouttap="bindcallouttap" bindmarkertap="markertap" style="width: 100%; height: {{view.Height}}px;" wx:if="{{hasMarkers}}" scale="10" ></map></view><view class="maptext" wx:if="{{mapList!=''}}"><view  class="news"><view wx:if="{{mapList.polylineJson!=null}}">预计<text style="color:#FF6565">{{now}}</text>送达</view><view class="tishi">由药店提供配送服务</view></view><view  class="phone_box"><view style="" class="right_box" data-phone="{{mapPhone}}" bindtap="makeCallPhone" wx:if="{{mapPhone!=null}}"><image src="{{imgUrl}}mapshop_phone.png"></image><view style="line-height:96rpx">联系商家</view></view><view  class="left_box" data-deliverhone="{{deliverPhone}}" bindtap="makesCallPhone" wx:if="{{deliverPhone!=null}}"><image src="{{imgUrl}}map_phone.png"></image><view style="line-height:96rpx">联系配送员</view></view></view></view>

js:

data: {longitude: '',latitude:'',points: [],polyline: [],markers: [],mapList:'',polylineList:[],},mapLine(options){wx.showLoading({title: '加载中',})let subOrderNo = options.maporderconsole.log(subOrderNo)let that=thislet token = that.data.storageData.tokenlet url = '接口地址';let params = {subOrderNo:subOrderNo};http.getRequest(url, params, token).then(res => {// 地图打点标记商家和配送员位置let markers= [{iconPath: imgUrl+'shoplong.png',id: 0,latitude: that.data.mapList.pharmacyInfo.latitude,longitude: that.data.mapList.pharmacyInfo.longitude,callout: { content: that.data.mapList.pharmacyInfo.pharmacyName+"已接单",name:"商家已接单",color: "#ff0000",fontSize: "16", borderRadius: "6",bgColor: "#ffffff",padding: "10",display:"ALWAYS"},width: 50,height: 50},{iconPath:imgUrl+ 'maplog.png',id: 1,latitude: that.data.mapList.locationList[0].latitude,longitude: that.data.mapList.locationList[0].longitude,callout: { content: "配送员正在配送",name:"正在配送",color: "#ff0000",fontSize: "16", borderRadius: "6",bgColor: "#ffffff",padding: "10",display:"ALWAYS"},width: 50,height: 50},];console.log(markers)let _this=this_this.setData({markers:markers,hasMarkers:true,latitude:that.data.mapList.pharmacyInfo.latitude,longitude:that.data.mapList.pharmacyInfo.longitude})if(orderDeliver.polylineJson!=null){let mapJson = JSON.parse(orderDeliver.polylineJson);console.log(mapJson)// 计算送达时间let mapDate=that.data.mapList.updateTimelet newsDate=new Date(mapDate)// let h = newsDate.getHours()let m = newsDate.getMinutes()let mapMinte=mapJson.route.paths[0].duration/60newsDate.setMinutes(m+mapMinte)let dd=newsDate.getMinutes()let hh=newsDate.getHours()if(dd<10){dd='0'+dd}if(hh<10){hh='0'+hh}let now=hh +':'+dd;if(newsDate.getMinutes()>=60){h=h+1;}else{this.setData({now:now})console.log(now)}// 循环数组取快递员的经纬度let list = mapJson.route.paths[0].steps;// console.log(list);let polylineList = [];   for(let i =0;i<list.length;i++){let polyline = list[i].polyline;if(polyline.indexOf(";") != -1){let pList = polyline.split(";");// console.log(pList)pList.map((items,index) =>{let a = items.split(",");polylineList.push({latitude: a[1],longitude: a[0]});// console.log(polylineList)})// polylineList.concat(pList);}}let polyline = [{points: polylineList,color: "#518FF8",width: 4,dottedLine: false}];this.setData({polyline:polyline,points:polylineList,}) }    }else if(res.responseCode == 0 && res.responseBody != null && res.responseBody.length != 0 && res.responseBody.deliverType ==2){let list_di=res.responseBody.deliverTypelet maplistJson=res.responseBody.polylineJsonlet listMap=JSON.parse(maplistJson)console.log(listMap)let logList=listMap.data.reverse()logList.forEach(element => {element.ftime = element.ftime.substring(0,16)});console.log(logList)this.setData({mapList:[],hasMarkers:false,logList:logList,list_di:list_di})// sysMsg.sysMsg("商家还未接单,请稍后查看", 2000, 'none');}else{sysMsg.sysMsg("商家还未接单,请稍后查看", 2000, 'none');}}).catch(err => {console.log(err);sysMsg.sysMsg("请求超时,请稍后再试", 1500, 'none');})},onLoad: function (options) {this.mapLine(options)this.mapHeight()this.mapLog()// this.markers()// console.log(options.maporder)this.getstorageDataToPage()// qq地图apiqqmapsdk = new QQMapWX({key: '申请的微信小程序地图key'});},

微信小程序地图实现展示路线路相关推荐

  1. 微信小程序 微信小程序地图搜索、地图搜索点点击出callout气泡标题说明

    实现效果:根据楼盘名称实现地图定位.周边搜索: 代码: html <view class="mapinfo"><view class="mapbd&qu ...

  2. 微信小程序地图获取地点信息(打卡签到功能为例)-2020-7-26

    目录 微信小程序地图获取地点信息(打卡签到功能为例) 效果图 前提步骤 首先需要了解的 代码部分 配置性代码 功能性代码 demo 下载 微信小程序地图获取地点信息(打卡签到功能为例) 解决方案:利用 ...

  3. 微信小程序地图插件系列(二):微信小程序使用百度地图(不定期补充知识点)

    前言 当我们在使用一些地图相关软件的情况下,他会显示选择那种.一般都有高德地图,百度地图等.那么我们在微信小程序中也想使用这种功能需要怎么办呢? 本文地址链接 微信小程序-百度地图SDK官方文档 微信 ...

  4. php小程序地图处理,微信小程序 地图map详解及简单实例

    微信小程序 地图map 微信小程序map 地图属性名类型默认值说明longitudeNumber中心经度 latitudeNumber中心纬度 scaleNumber1缩放级别 markersArra ...

  5. php小程序地图处理,微信小程序地图 map

    微信小程序地图 map 微信小程序map 地图 标记点 标记点用于在地图上显示标记的位置,不能自定义图标和样式 覆盖物 覆盖物用于在地图上显示自定义图标,可自定义图标和样式 地图组件的经纬度必填, 如 ...

  6. 微信小程序获取并展示公众号推文

    微信小程序获取并展示公众号推文 获取公众号access_token(开发环境) IP白名单设置 获取access_token 小程序前端展示 素材导入云数据库 云函数读取展示 注:笔者是小程序菜鸟,代 ...

  7. 微信小程序地图组件和相机组件实现基于location的AR效果的尝试(失败)

    微信小程序地图组件和相机组件实现基于location的AR效果的尝试(失败) 最近无论AR还是微信小程序都是炒的火热.微信小程序的特点便是"无需安装,用完即走",而我们所说的AR用 ...

  8. 微信小程序--地图上添加图片

    如何在微信小程序地图添加上,添加图片? 在微信小程序中,地图的层级最高,所以我们没有办法,通过定位,在地图上添加图片等信息; 处理办法: 添加控件:controls; 其中有个属性position,进 ...

  9. 微信小程序---地图导航(点击地址,可以进行导航)

    微信小程序-地图导航(点击地址,可以进行导航) // 地图getLocation(e){var that = this,address = e.currentTarget.dataset.addres ...

  10. 微信小程序地图使用用户头像标记

    一.在开发微信小程序地图的过程中,有这样一个需求,用户发表祝福语,然后存入数据库,可以在地图上显示用户头像并且点击用户头像时显示祝福语. 二.自己在开发时遇到的问题: 1.微信头像是网络图片,而地图的 ...

最新文章

  1. 关于readdir返回值中struct dirent.d_type的取值有关问题(转)
  2. 【数理知识】《积分变换与场论》王振老师-第5章-场论
  3. 物联网平台构架系列 (四):Amazon, Microsoft, IBM IoT 解决方案导论 之 平台
  4. pod 的亲和性,反亲和性 实验
  5. ASP.NET 安全认证(三)—— 用Form 表单认证实现单点登录(Single Sign On) .
  6. react构建_您应该了解的有关React的一切:开始构建所需的基础知识
  7. 前端学习(3288):react hook state-hook
  8. 微信公众号教程(8)用微信开发模式做欢迎词
  9. ardupilot在Linux上设置SITL(FlightGear)
  10. Java自学指南一、找一个开始并能坚持下去的理由
  11. 【SharePoint】通过CAML Query查询SharePoint User or Group列(人员和用户组字段)
  12. union和union all哪个效率高
  13. python数据分析09_pandas数据聚合与分组运算
  14. (六)Graphics基本应用
  15. css动画transition和animation实现遮罩动画
  16. IR PC IP 之义
  17. 数据结构(八):排序 | 插入排序 | 希尔排序 | 冒泡排序 | 快速排序 | 简单选择排序 | 堆排序 | 归并排序 | 基数排序 | 外部排序 | 败者树 | 置换-选择排序 | 最佳归并树
  18. Vue实现Google登录
  19. Blender基础:多边形建模中F命令和J命令的区别
  20. WLAN从入门到精通—STA接入过程

热门文章

  1. Windows安装镜像下载
  2. Galaxy S III 新广告大片:All Share功能 完败iPhone!
  3. HTTP、HTTP2.0、SPDY、HTTPS 你应该知道的一些事
  4. Oracle项目管理系统之供应商筛选及资格预审
  5. android黑色半透明dialog背景,Dialog背景半透明
  6. vue当前浏览器是否为ie_vue判断当前浏览器为IE低版本,给出升级提示;IE11及其他浏览器正常使用...
  7. html水平垂直居中
  8. 数据库MySQL学习心得
  9. stl文件用proe怎么打开_stl格式怎么打开
  10. DOM元素节点属性outerHTML和innerHTML