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() // 取消請求任務
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、利用循環獲取模板並展示