一、效果圖
二、操作步驟
1、申請(qǐng)騰訊地圖key――地址
2、小程序后臺(tái)添加騰訊插件――開發(fā)文檔
3、小程序代碼app.json設(shè)置
let plugin = requirePlugin("routePlan"); let key = ""; //使用在騰訊位置服務(wù)申請(qǐng)的key let referer = ""; //調(diào)用插件的app的名稱 let endPoint = JSON.stringify({ //終點(diǎn) "name": "吉野家(北京西站北口店)", "latitude": 39.89631551, "longitude": 116.323459711 }); wx.navigateTo({ url: "plugin://routePlan/index?key=" + key + "&referer=" + referer + "&endPoint=" + endPoint });
或者也可以使用小程序內(nèi)置地圖導(dǎo)航
使用小程序內(nèi)置地圖wx.getLocation和wx.openLocation
官網(wǎng)鏈接
//wxml <button type="default" bindtap="openMap">打開地圖</button>
//js Page({ data: { }, openMap: function () { wx.getLocation({ type: "gcj02", // 默認(rèn)為 wgs84 返回 gps 坐標(biāo),gcj02 返回可用于 wx.openLocation 的坐標(biāo) success: function (res) { // success console.log(res.latitude); console.log(res.longitude); wx.openLocation({ latitude: res.latitude, // 緯度,范圍為-90~90,負(fù)數(shù)表示南緯 longitude: res.longitude, // 經(jīng)度,范圍為-180~180,負(fù)數(shù)表示西經(jīng) scale: 28, // 縮放比例 name:"要找的地方名字(某某飯店)", address:"地址:要去的地點(diǎn)詳細(xì)描述" }) } }) } })
總結(jié)
到此這篇關(guān)于微信小程序實(shí)現(xiàn)導(dǎo)航功能的文章就介紹到這了,更多相關(guān)微信小程序?qū)Ш焦δ軆?nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://juejin.cn/post/6935723970658467876