微信公众号点击打开地图导航

html 复制代码
<h3 id="menu-location">地理位置接口</h3>
 <span class="desc">使用微信内置地图查看位置接口</span>
 <button class="btn btn_primary" id="openLocation">openLocation</button>
<span class="desc">获取地理位置接口</span>
      <button class="btn btn_primary" id="getLocation">getLocation</button>
       
<script>
//这里的配置详细可以看帮助
wx.config({
      debug: false,
      appId: 'wxf8b4f85f3a794e77',
      timestamp: 1522828107,
      nonceStr: 'jnShs2vgPDo6fwlY',
      signature: '1432d01387adacbca1ce0a4d6ecf3f62363e0309',
      jsApiList: [
      // 所有要调用的 API 都要加到这个列表中        
        'openLocation',
        'getLocation',    
]
  });
  wx.ready(function () {
    // 在这里调用 API
     // 7 地理位置接口
  // 7.1 查看地理位置
  document.querySelector('#openLocation').onclick = function () {
    wx.openLocation({
      latitude: 23.099994,
      longitude: 113.324520,
      name: 'TIT 创意园',
      address: '广州市海珠区新港中路 397 号',
      scale: 14,
      infoUrl: 'http://weixin.qq.com'
    });
  };
  // 7.2 获取当前地理位置
  document.querySelector('#getLocation').onclick = function () {
    wx.getLocation({
      success: function (res) {
        alert(JSON.stringify(res));
      },
      cancel: function (res) {
        alert('用户拒绝授权获取地理位置');
      }
    });
  };
  });
</script>
相关推荐
呵呵哒( ̄▽ ̄)"32 分钟前
React - 编写选择礼物组件
前端·javascript·react.js
User_芊芊君子36 分钟前
【Java面试题】——this 和 super 的区别
java·开发语言
柴薪之王、睥睨众生37 分钟前
(自用)Java学习-5.8(总结,springboot)
java·开发语言·spring boot·学习·mybatis
牛马baby37 分钟前
Java高频面试之并发编程-17
java·开发语言·面试
让我们一起加油好吗37 分钟前
【C++】模板(初阶)
开发语言·c++·visualstudio·模板·泛型编程
灏瀚星空2 小时前
基于Python的量化交易实盘部署与风险管理指南
开发语言·python
Run_Teenage2 小时前
C++类和对象:运行符重载、取地址运算符重载、const 修饰的类如何作为参数
开发语言·c++
一只小bit2 小时前
More Effective C++:改善编程与设计(上)
开发语言·c++·方法·技巧
钢铁男儿3 小时前
C# 方法(栈帧)
开发语言·c#
忆源5 小时前
【Qt】之音视频编程1:QtAV的背景和安装篇
开发语言·qt·音视频