likes
comments
collection
share

微信小程序实现导航功能

作者站长头像
站长
· 阅读数 19

一、效果图

微信小程序实现导航功能

二、操作步骤

1、申请腾讯地图key——地址

2、小程序后台添加腾讯插件——开发文档

微信小程序实现导航功能

3、小程序代码app.json设置

微信小程序实现导航功能

let plugin = requirePlugin('routePlan');
let key = '';  //使用在腾讯位置服务申请的key
let referer = '';   //调用插件的app的名称
let endPoint = JSON.stringify({  //终点
    'name': '吉野家(北京西站北口店)',
    'latitude': 39.89631551,
    'longitude': 116.323459711
});
wx.navigateTo({
    url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
});

或者也可以使用小程序内置地图导航

使用小程序内置地图wx.getLocation和wx.openLocation

微信小程序实现导航功能 微信小程序实现导航功能

官网链接

//wxml
<button type="default" bindtap="openMap">打开地图</button>
//js
Page({
  data: {

  },
  openMap: function () {
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
      success: function (res) {
        // success
        console.log(res.latitude);
        console.log(res.longitude);
        wx.openLocation({
          latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬
          longitude: res.longitude, // 经度,范围为-180~180,负数表示西经
          scale: 28, // 缩放比例
          name:"要找的地方名字(某某饭店)",
          address:"地址:要去的地点详细描述"
        })
      }
    })
  }
})
转载自:https://juejin.cn/post/6935723970658467876
评论
请登录