微信小程序開發相關記錄(2017.07.23)

1、獲取位置的API


這裏是獲取到位置,並且打開地圖定位到手機當前的經緯度座標處

wx.getLocation({
  type: 'gcj02', //返回可以用於wx.openLocation的經緯度
  success: function(res) {
    var latitude = res.latitude
    var longitude = res.longitude
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      scale: 28
    })
  }
})

2、發起網絡請求的API


const requestTask = wx.request({
  url: 'test.php', //僅爲示例,並非真實的接口地址
  data: {
     x: '' ,
     y: ''
  },
  header: {
      'content-type': 'application/json'
  },
  success: function(res) {
    console.log(res.data)
  }
})

requestTask.abort() // 取消請求任務


3、根據經緯度座標獲取城市信息的接口地址(百度API):

http://api.map.baidu.com/geocoder/v2/?ak=百度API Key&location=32.12,120.5&output=json


4、根據城市名稱獲取天氣信息的接口地址:

http://wthrcdn.etouch.cn/weather_mini?city=合肥



5、頁面js方法調用,在微信API方法內調用另一個方法,要首先獲取到當前的頁面,如下圖所示:

var page = this;


6、獲取返回的Json值後,可以在頁面中直接.出對應節點的值,如下圖所示:

首先創建數組



7、使用模板API,定義與引用




創建模板



8、利用循環獲取模板並展示


發佈了578 篇原創文章 · 獲贊 298 · 訪問量 204萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章