国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序---- 外賣小程序查看實時地圖路線(騎手端&用戶端)【高德地圖】

這篇具有很好參考價值的文章主要介紹了微信小程序---- 外賣小程序查看實時地圖路線(騎手端&用戶端)【高德地圖】。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

微信小程序---- 外賣小程序查看地圖路線(騎手端&用戶端)【高德地圖】

前言:1. 在小程序中需要使用map組件,文檔鏈接:https://developers.weixin.qq.com/miniprogram/dev/component/map.html
2.使用的是高德地圖,所以需要引進相關的js,下載鏈接:https://lbs.amap.com/api/wx/download
3.去往高德官方申請需要用的key,操作鏈接:https://lbs.amap.com/api/wx/guide/create-project/get-key/

html

<map id="map" style="width: 100%;height: 100vh;" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" scale="{{scale}}" polyline="{{polyline}}" show-location enable-zoom>
      <cover-view id="top">
        <cover-view class="ibody">
          <cover-view class="leftz">
            <cover-view>預計時長:{{duration}}分鐘</cover-view>
          </cover-view>
          <cover-view class="leftz leftz1">           
            <cover-view>剩余公里數(shù):{{distance}}米</cover-view>
          </cover-view>
        </cover-view>
      </cover-view>
  </map>

JS ( tag 1是司機端進入查看 2是用戶端身份查看)

import {
  showdriverupdata,
  getdata,
  updata
} from '../server/post';
var amapFile = require('../../common/amap-wx.130.js'); //引入高德js
Page({
  data: {
    tag: 1, //1是小車身份進入查看 2是特殊商戶身份查看
    latitude: '', //起始經(jīng)度
    longitude: '', //終點緯度
    zhongdianjingdu: '', //終點經(jīng)度
    zhongdianweidu: '', //終點緯度
    scale: 12,
    markers: [{
      iconPath: "../../image/car.png",
      id: 0,
      latitude: '',
      longitude: '',
      width: 33,
      height: 30
    }, {
      iconPath: "../../image/end.png",
      id: 1,
      latitude: '',
      longitude: '',
      width: 35,
      height: 40
    }],
    distance: '',
    polyline: [],
    scatterlongitude: '', //特殊商戶身份 單個小車位置的經(jīng)緯度
    timer: null,
  },
  onLoad: function (options) {
    this.setData({
      tag: options.tag || 1,
      scatterlongitude: options.scatterlongitude,
      timer:null
    })
    clearInterval(this.data.timer);
  },
  onShow() {
    this.getCarinfo();
  },

  // 高德地圖劃線
  getDrivingRoute(origin, destination) {
    var that = this;
    var myAmapFun = new amapFile.AMapWX({
      key: 'XXXXXXXXXX'
    });
    myAmapFun.getDrivingRoute({
      origin: origin,
      destination: destination,
      success: function (data) {
        console.log('高德劃線數(shù)據(jù)-----', data)
        var points = [];
        if (data.paths && data.paths[0] && data.paths[0].steps) {
          var steps = data.paths[0].steps;
          for (var i = 0; i < steps.length; i++) {
            var poLen = steps[i].polyline.split(';');
            for (var j = 0; j < poLen.length; j++) {
              points.push({
                longitude: parseFloat(poLen[j].split(',')[0]),
                latitude: parseFloat(poLen[j].split(',')[1])
              })
            }
          }
        }
        that.setData({
          polyline: [{
            points: points,
            color: "#0091ff",
            width: 6
          }]
        });
        if (data.paths[0] && data.paths[0].distance) { //公里數(shù)
          that.setData({
            distance: data.paths[0].distance
          });
        }
        if (data.paths[0] && data.paths[0].duration) { //花費時間
          let miu = parseInt(Number(data.paths[0].duration) / 60)
          that.setData({
            duration: miu
          });
        }
      },
      fail: function (info) {

      }
    })
  },

  //這個函數(shù)是一開始點擊事件觸發(fā)的:
  async authorization() {
    let that = this;
    try { //等待
      await this.getWxLocation() //小車身份
    } catch (error) {
      wx.showModal({
        title: '溫馨提示',
        tip: '獲取權限失敗,是否授權獲取地理位置?',
        showCancel: true,
        confirmText: '授權位置',
        cancelText: '取消',
        sureCall() {
          that.openSetting()
        },
        cancelCall() {}
      })
      return
    }
  },

  // 獲取當前位置 (小車身份調(diào)用)
  getWxLocation() {
    let that = this,
      v = that.data;
    wx.showLoading({
      title: '定位中...',
      mask: true,
    })
    return new Promise((resolve, reject) => {
      let _locationChangeFn = (res) => {
        console.log('location change', res)
        let sonlinecopyId = wx.getStorageSync('lineId');
        const latitude = res.latitude;
        const longitude = res.longitude;
        let origin = longitude + ',' + latitude; //將經(jīng)緯度拼接
        let destination = v.zhongdianweidu + ',' + v.zhongdianjingdu;
        console.log('當前經(jīng)緯度---', origin)
        that.setData({
          latitude,
          longitude,
          ['markers[0].latitude']: latitude,
          ['markers[0].longitude']: longitude,
          ['markers[1].latitude']: v.zhongdianjingdu,
          ['markers[1].longitude']: v.zhongdianweidu,
        })

        that.getDrivingRoute(origin, destination); //路況劃線
        //小車增加當前位置經(jīng)緯度 latitude緯度
        updata(sonlinecopyId, latitude, longitude).then(res => {
          console.log('小車增加當前位置經(jīng)緯度----', latitude, longitude)
          wx.hideLoading();
        })
        // wx.offLocationChange(_locationChangeFn)
      }
      wx.startLocationUpdate({
        success: (res) => {
          wx.onLocationChange(_locationChangeFn)
          resolve()
        },
        fail: (err) => {
          console.log('獲取當前位置失敗', err)
          wx.hideLoading()
          reject()
        }
      })
    })
  },

  // 開啟權限
  openSetting() {
    let self = this
    wx.openSetting({
      success(res) {
        console.log(res)
        if (res.authSetting["scope.userLocation"]) {
          // res.authSetting["scope.userLocation"]為trueb表示用戶已同意獲得定位信息,此時調(diào)用getlocation可以拿到信息
          self.authorization()
        }
      }
    })
  },


  // 特殊商戶身份 獲取小車經(jīng)緯度
  getsmallCar() {
    wx.showLoading({
      title: '獲取中...',
      mask: true,
    })
    let copyId = wx.getStorageSync('lineId');
    let v = this.data;
    v.timer = setInterval(() => {
      getdata(copyId).then(res => {
        if (res.data.code != 500) {
          let datas = res.data.data;
          let latitude = '',
            longitude = "";

          if (datas.msg == "未獲取到司機實時位置!") {
            let arr = [];
            arr = v.scatterlongitude.split(',');
            latitude = arr[1];
            longitude = arr[0];
          } else {
            datas.weidu > 90 ? (latitude = datas.jingdu, longitude = datas.weidu) :
              (latitude = datas.weidu, longitude = datas.jingdu);
          }
          this.setData({
            latitude,
            longitude,
            ['markers[0].latitude']: latitude,
            ['markers[0].longitude']: longitude,
            ['markers[1].latitude']: v.zhongdianjingdu,
            ['markers[1].longitude']: v.zhongdianweidu,
          })

          let origin = longitude + ',' + latitude;
          let destination = v.zhongdianweidu + ',' + v.zhongdianjingdu;
          console.log('特殊商戶身份 獲取小車經(jīng)緯度--', origin)
          this.getDrivingRoute(origin, destination); //路況劃線
          wx.hideLoading();
        }else{
          wx.hideLoading();
          wx.showToast({
            title: '網(wǎng)絡繁忙,請稍后再試!',
            icon:'none'
          })
        }
      })
    }, 5000);
  },

  // 獲取小車信息
  getCarinfo() {
    let that = this;
    let sonlinecopyId = wx.getStorageSync('lineId');
    showdriverupdata(sonlinecopyId).then(res => {

      let datas = res.data.data;
      this.setData({
        carnub: datas.chepaihao,
        driverName: datas.driverName,
        begintime: datas.kaishi,
        peisonging: datas.peisongzhong,
        peisonglist: datas.daipeisong,
        zhongdianjingdu: datas.zhongdianjingdu,
        zhongdianweidu: datas.zhongdianweidu
      })
      // this.getLocation();

      console.log('小車信息----', datas);
      // that.authorization(); //小車身份地圖
      if (that.data.tag == 1) {
        that.authorization(); //小車身份地圖
      } else {
        that.getsmallCar() //特殊商戶身份
      }

    })
  },

  onUnload() {
    clearInterval(this.data.timer);
  },
  onHide: function () {
    clearInterval(this.data.timer);
  },

})

微信小程序物流地圖,微信小程序,小程序,微信小程序,前端文章來源地址http://www.zghlxwxcb.cn/news/detail-597161.html

到了這里,關于微信小程序---- 外賣小程序查看實時地圖路線(騎手端&用戶端)【高德地圖】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • uniapp實現(xiàn)微信小程序用戶實時位置定位并顯示地圖

    uniapp實現(xiàn)微信小程序用戶實時位置定位并顯示地圖

    目前,我們可以通過一些現(xiàn)成的api來實現(xiàn)此功能。下面我將介紹一下通過騰訊位置服務來實現(xiàn)此功能的具體操作流程。 1、在Hbuilder x中對項目進行權限開放 進入到manifest.json文件中 ? 2、獲取調(diào)用騰訊位置服務所需的key 登錄騰訊地圖api: 騰訊位置服務 - 立足生態(tài),連接未來

    2024年02月09日
    瀏覽(90)
  • 微信小程序?qū)W習實錄6(百度經(jīng)緯度采集、手動調(diào)整精度、H5嵌入小程序、百度地圖jsAPI、實時定位、H5更新自動刷新)

    微信小程序?qū)W習實錄6(百度經(jīng)緯度采集、手動調(diào)整精度、H5嵌入小程序、百度地圖jsAPI、實時定位、H5更新自動刷新)

    viewport,手機端的適配; layui,手機端界面UI; jweixin-1.6.0,H5與微信小程序通信的API接口文件 getBdGeo ();定位封裝函數(shù); marker.addEventListener(\\\'dragend\\\', function () {}, 監(jiān)聽標注事件,手動調(diào)整景點 getCurrentPosition, 加載即自動采集當前位置的經(jīng)緯度信息和城市地址信息; 通過web-view

    2024年02月05日
    瀏覽(30)
  • 基于微信小程序的外賣小程序+ssm

    基于微信小程序的外賣小程序+ssm

    社會的發(fā)展和科學技術的進步,互聯(lián)網(wǎng)技術越來越受歡迎。手機也逐漸受到廣大人民群眾的喜愛,也逐漸進入了每個用戶的使用。手機具有便利性,速度快,效率高,成本低等優(yōu)點。 因此,構建符合自己要求的操作系統(tǒng)是非常有意義的。 本文從管理員、用戶和商家的功能要

    2024年01月18日
    瀏覽(24)
  • 【微信小程序】外賣點餐效果展示

    【微信小程序】外賣點餐效果展示

    外賣點餐效果展示,左右布局,快速點餐,商家信息展示等...程序是模仿人家的,所以界面沒做什么調(diào)整,功能是沒啥問題,可以正常使用... 直接看效果圖: 可以把這個點餐這個功能分為5部分組成 1、第一部分頭部信息 2、第二部分左布局 3、第三部分右布局 4、第四部分點

    2024年02月08日
    瀏覽(25)
  • 微信小程序餐飲外賣系統(tǒng)設計與實現(xiàn)

    摘 要 隨著現(xiàn)在的“互聯(lián)網(wǎng)+”的不斷發(fā)展。現(xiàn)在傳統(tǒng)的餐飲業(yè)也朝著網(wǎng)絡化的方向不斷的發(fā)展?,F(xiàn)在線上+線下的方式來實現(xiàn)餐飲的獲客渠道增加,可以更好地幫助餐飲企業(yè)實現(xiàn)更多、更廣的獲客需求,實現(xiàn)更好的餐飲銷售。截止到2021年末,我國的外賣市場已經(jīng)突破萬億,高

    2024年02月10日
    瀏覽(15)
  • 規(guī)劃路線(微信小程序、H5)
  • 基于微信小程序的外賣點餐小程序

    基于微信小程序的外賣點餐小程序

    文末聯(lián)系獲取源碼 開發(fā)語言:Java 框架:ssm JDK版本:JDK1.8 服務器:tomcat7 數(shù)據(jù)庫:mysql 5.7/8.0 數(shù)據(jù)庫工具:Navicat11 開發(fā)軟件:eclipse/myeclipse/idea Maven包:Maven3.3.9 瀏覽器:谷歌瀏覽器 小程序框架:uniapp 小程序開發(fā)軟件:HBuilder X 小程序運行軟件:微信開發(fā)者 隨著信息技術在管

    2024年02月09日
    瀏覽(20)
  • springboot基于微信小程序的外賣系統(tǒng)小程序

    springboot基于微信小程序的外賣系統(tǒng)小程序

    專業(yè)技術開發(fā),收藏關注不迷路 自從計算機發(fā)展開始,計算機軟硬件相關技術的發(fā)展速度越來越快,在信息化高速發(fā)展的今天,計算機應用技術似乎已經(jīng)應用到了各個領域。在餐飲行業(yè),除了外賣以外就是到店里就餐,在店里就餐如果需要等待點餐的話,用戶的體驗度就會急

    2024年02月03日
    瀏覽(20)
  • 微信小程序?qū)崿F(xiàn)路線規(guī)劃demo

    微信小程序?qū)崿F(xiàn)路線規(guī)劃demo

    本文旨在以mpvue框架為基礎,探討地圖類小程序的開發(fā)思路。 原作者利用mpvue + 騰訊地圖的能力做了一個地鐵路線規(guī)劃的小程序,主要提供全球主要城市的地鐵線網(wǎng)圖及旅游介紹,其中國內(nèi)城市支持查看地圖和路線規(guī)劃。 目前騰訊位置服務也推出了路線規(guī)劃插件、地鐵圖插件

    2024年02月08日
    瀏覽(19)
  • 微信小程序畢業(yè)設計作品成品(75)微信小程序在線外賣點餐系統(tǒng)設計與實現(xiàn)

    微信小程序畢業(yè)設計作品成品(75)微信小程序在線外賣點餐系統(tǒng)設計與實現(xiàn)

    博主介紹: 《Vue.js入門與商城開發(fā)實戰(zhàn)》《微信小程序商城開發(fā)》圖書作者,CSDN博客專家,在線教育專家,CSDN鉆石講師;專注大學生畢業(yè)設計教育和輔導。 所有項目都配有從入門到精通的基礎知識視頻課程,免費 項目配有對應開發(fā)文檔、開題報告、任務書、PPT、論文模版

    2024年02月08日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包