Page({
onReady: function (e) { // 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
getCenterLocation: function () {
this.mapCtx.getCenterLocation({
success: function(res){
console.log(res.longitude)
console.log(res.latitude)
}
})
},
})
//我的代码
onLoad: function (options) {
var that = this;
that.mapCtx = wx.createMapContext(‘myMap’);
// 获取当前位置并移动到此位置
wx.getLocation({
success: function (res) {
var longitude = res.longitude;
var latitude = res.latitude;
// console.log(res)
that.setData({
longitude: longitude,
latitude: latitude
})
setTimeout(function () {
that.mapCtx.moveToLocation();
}, 300);
}
});
},
onShow: function () {
var that = this;
// 获取中心位置
console.log(that.mapCtx);
that.mapCtx.getCenterLocation({
success: function (res) {
console.log(res);
var centerLgt = res.longitude;
var centerLat = res.latitude;
if (centerLgt == that.data.centerLgt && centerLat == that.data.centerLat) {
return;
} else {
that.setData({
centerLgt: centerLgt,
centerLat: centerLat
});
getMarkers.call(that, centerLat, centerLgt);
}
}
});
},
//console返回的结果
是什么原因造成的呢?