1. 程式人生 > >【微信小程式】 按鈕觸發地圖呼叫

【微信小程式】 按鈕觸發地圖呼叫

wxml

<button id="0" type="primary" bindtap="listenerBtnGetLocation">定位當前位置並開啟內建地圖</button>
  • 1

js

Page({
  data:{
    text:"Page location"
  },
  onLoad:function(options){
    // 頁面初始化 options為頁面跳轉所帶來的引數
  },

  /**
   * 監聽定位到當前位置
   */
  listenerBtnGetLocation: function() {
    wx.getLocation({
      //定位型別 wgs84, gcj02
type: 'gcj02', success: function(res) { console.log(res) wx.openLocation({ //當前經緯度 latitude: res.latitude, longitude: res.longitude, //縮放級別預設28 scale: 28, //位置名 name: '測試地址', //詳細地址 address: '火星路24號'
, //成功列印資訊 success: function(res) { console.log(res) }, //失敗列印資訊 fail: function(err) { console.log(err) }, //完成列印資訊 complete: function(info){ console.log(info) }, }) }, fail: function
(err) {
console.log(err) }, complete: function(info) { console.log(info) }, }) }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關閉 } })