data: {
},
getCenterLocation: function() {
this.mapCtx.getCenterLocation({
success: function(res) {
console.log(res.longitude)
console.log(res.latitude)
}
})
},
/**
仔细检查下完整的代码,getCenterLocation写的位置不正确
onLoad: function () {//http://www.imooc.com/wenda/detail/486087 异步调用
// this.on();
var that = this
var wei=this.lc(function(wei){
console.log(wei);
wx.request({
url: 'http://localhost:3030/66/servlet/nr',
method: 'get',
data: {
latitude: wei.latitude,
//longitude:longitude,
//longitude: wei.longitude
longitude:wei.longitude,
},
header: {
'content-type': 'application/json' // 默认值
// 'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
that.setData({ nr6: res.data });
//var json=JSON.parse(res.data);
//console.log(res.data[0].id);
},
fail: function (res) {
console.log(".....fail.....");
}
})
});
},
lc: function (wei) {
var self = this
wx.getLocation({
type: 'wgs84',
success: function (res) {
//console.log(res);
// var latitude = res.latitude;
// getApp().globalData.latitude = res.latitude;
// getApp().globalData.longitude = res.longitude;
//var longitude = res.longitude;
//self.setData({
// latitude: latitude,
// longitude: longitude//buyong在上面的data中初始化变量,在这set
// })
//console.log(latitude);
//弹框
wei(res);
return wei;
}
})
这是我的例子 希望能帮到有问题的人