微信小程序实现导航功能操作代码示例

作者:袖梨 2021-03-10

本篇文章小编给大家分享一下微信小程序实现导航功能操作代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

一、效果图

二、操作步骤

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

//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:"地址:要去的地点详细描述"
  })
  }
 })
 }
})

相关文章

精彩推荐