微信小程序地圖實(shí)現(xiàn)展示線路
本文實(shí)例為大家分享了微信小程序地圖實(shí)現(xiàn)展示線路的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:

思路:
1、首先獲取一系列的坐標(biāo)點(diǎn),然后將這些坐標(biāo)從頭到尾鏈接起來(lái)。(參考微信小程序地圖組件polyline屬性)
2、在獲取的坐標(biāo)點(diǎn)上標(biāo)注某一個(gè)位置,實(shí)現(xiàn)打點(diǎn)。(參考微信小程序地圖組件marker屬性 )
3、使用map組件
下面直接展示代碼:
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}}">預(yù)計(jì)<text style="color:#FF6565">{{now}}</text>送達(dá)</view>
<view class="tishi">由藥店提供配送服務(wù)</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">聯(lián)系商家</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">聯(lián)系配送員</view>
</view>
</view>
</view>
js:
data: {
longitude: '',
latitude:'',
points: [],
polyline: [],
markers: [],
mapList:'',
polylineList:[],
},
mapLine(options){
wx.showLoading({
title: '加載中',
})
let subOrderNo = options.maporder
console.log(subOrderNo)
let that=this
let token = that.data.storageData.token
let url = '接口地址';
let params = {
subOrderNo:subOrderNo
};
http.getRequest(url, params, token).then(res => {
// 地圖打點(diǎn)標(biāo)記商家和配送員位置
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)
// 計(jì)算送達(dá)時(shí)間
let mapDate=that.data.mapList.updateTime
let newsDate=new Date(mapDate)
// let h = newsDate.getHours()
let m = newsDate.getMinutes()
let mapMinte=mapJson.route.paths[0].duration/60
newsDate.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)
}
// 循環(huán)數(shù)組取快遞員的經(jīng)緯度
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.deliverType
let maplistJson=res.responseBody.polylineJson
let 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("商家還未接單,請(qǐng)稍后查看", 2000, 'none');
}else{
sysMsg.sysMsg("商家還未接單,請(qǐng)稍后查看", 2000, 'none');
}
}).catch(err => {
console.log(err);
sysMsg.sysMsg("請(qǐng)求超時(shí),請(qǐng)稍后再試", 1500, 'none');
})
},
onLoad: function (options) {
this.mapLine(options)
this.mapHeight()
this.mapLog()
// this.markers()
// console.log(options.maporder)
this.getstorageDataToPage()
// qq地圖api
qqmapsdk = new QQMapWX({
key: '申請(qǐng)的微信小程序地圖key'
});
},
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開(kāi)發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序 地圖定位簡(jiǎn)單實(shí)例
- 微信小程序 地圖(map)實(shí)例詳解
- 微信小程序 使用騰訊地圖SDK詳解及實(shí)現(xiàn)步驟
- 微信小程序中進(jìn)行地圖導(dǎo)航功能的實(shí)現(xiàn)方法
- 微信小程序 高德地圖SDK詳解及簡(jiǎn)單實(shí)例(源碼下載)
- 微信小程序 地圖map詳解及簡(jiǎn)單實(shí)例
- 微信小程序開(kāi)發(fā)之map地圖實(shí)現(xiàn)教程
- 微信小程序教程之本地圖片上傳(leancloud)實(shí)例詳解
- 微信小程序之獲取當(dāng)前位置經(jīng)緯度以及地圖顯示詳解
- 微信小程序開(kāi)發(fā)之從相冊(cè)獲取圖片 使用相機(jī)拍照 本地圖片上傳
相關(guān)文章
詳解微信小程序-canvas繪制文字實(shí)現(xiàn)自動(dòng)換行
這篇文章主要介紹了微信小程序canvas繪制文字實(shí)現(xiàn)自動(dòng)換行,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
JavaScript實(shí)現(xiàn)購(gòu)物車(chē)圖片局部放大預(yù)覽效果
這篇文章主要為大家詳細(xì)介紹了JavaScript如何通過(guò)canvas簡(jiǎn)單實(shí)現(xiàn)購(gòu)物車(chē)圖片放大預(yù)覽效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-03-03
一文詳解Canvas實(shí)現(xiàn)打飛字游戲過(guò)程示例
這篇文章主要為大家介紹了Canvas實(shí)現(xiàn)打飛字游戲示例過(guò)程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
解決js數(shù)據(jù)包含加號(hào)+通過(guò)ajax傳到后臺(tái)時(shí)出現(xiàn)連接錯(cuò)誤
測(cè)試過(guò)程中發(fā)現(xiàn)js數(shù)據(jù)包含加號(hào)+通過(guò)ajax傳到后臺(tái)時(shí)出現(xiàn)連接錯(cuò)誤,刪除+,鏈接暢通了,果然是這塊問(wèn)題,對(duì)加號(hào)進(jìn)行轉(zhuǎn)義2013-08-08
javascript構(gòu)造函數(shù)以及原型對(duì)象的理解
本文主要介紹了javascript構(gòu)造函數(shù)以及原型對(duì)象的理解。分享了有關(guān)它們的實(shí)例代碼,具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
利用javaScript實(shí)現(xiàn)點(diǎn)擊輸入框彈出窗體選擇信息
這篇文章主要是對(duì)利用javaScript實(shí)現(xiàn)點(diǎn)擊輸入框彈出窗體選擇信息進(jìn)的實(shí)例行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12

