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

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>
相关推荐
摘星编程10 分钟前
React Native for OpenHarmony 实战:ImageBackground 背景图片详解
javascript·react native·react.js
低频电磁之道13 分钟前
编译C++的几种方式(MSVC编译器)
开发语言·c++
Zsy_05100318 分钟前
【C++】类和对象(一)
开发语言·c++
星火开发设计1 小时前
Java面向对象三大特性:封装、继承与多态的深度解析及实战
java·开发语言·microsoft·多态·继承·面向对象·封装
摘星编程1 小时前
React Native for OpenHarmony 实战:Alert 警告提示详解
javascript·react native·react.js
Joe5561 小时前
vue2 + antDesign 下拉框限制只能选择2个
服务器·前端·javascript
旅途中的宽~1 小时前
【Python】pip install -v e .命令不想自动更新torch版本
开发语言·python·pip
lly2024061 小时前
Vue3 指令详解
开发语言
WHS-_-20222 小时前
Tx and Rx IQ Imbalance Compensation for JCAS in 5G NR
javascript·算法·5g
摘星编程2 小时前
React Native for OpenHarmony 实战:GestureResponderSystem 手势系统详解
javascript·react native·react.js