本文只介绍如何使用天地图api,如若要显示天地图,使用 web-view
1、使用wx.request 发送请求
getLocation() {
wx.getLocation({
type: "gcj02",
success: (res) => {
this.initTianDiMap(res.longitude, res.latitude)
},
fail: (err) => {
console.log("err", err);
}
})
}
initTianDiMap(longitude, latitude) {
let that = this
wx.request({
url: "http://api.tianditu.gov.cn/geocoder",
data: {
postStr: JSON.stringify({"lon":longitude,"lat":latitude,"ver":1}),
type: "geocode",
tk: "2826428fe95fecce4433373ebf0d9945"
},
success: function (res) {
console.log(143, res.data);
},
fail: function (res) {
console.log(res.errMsg);
}
})
},