wx.request({
url: config.projectUrl + '/applets/getGoodsByGoodId',
data: {
goodId: goodId,
},
method: 'GET',
header: {
'content-type': 'application/json' //默认值
},
success:function(e){
var myLocationlatitude;
var myLocationlongitude;
var shop = e.data.shop;
var good = e.data.good;
//获取用户位置
wx.getLocation({
success: function (res) {
myLocationlatitude = res.latitude,
myLocationlongitude = res.longitude
},
fail: function () {
console.log("2处调用位置失败");
}
})
var markers = [
{ //自己位置markers
iconPath: '/img/我的位置.png',
id: 0,
latitude: myLocationlatitude,
longitude: myLocationlongitude,
width: 50,
height: 50,
callout: {
content: "我的位置",
color: "#FF0000",
fontSize: 15,
borderRadius: 5,
bgColor: "#FFFFFF",
display: "ALWAYS",
padding: 5,
textAlign: "center"
}
},
{
//iconPath: '/img/01.jpg',
id: 1,
latitude: shop.latitude,
longitude: shop.longtitude,
width: 20,
height: 35,
callout: {
content: good.name,
color: "#000000",
fontSize: 15,
borderRadius: 5,
bgColor: "#FFFFFF",
display: "ALWAYS",
padding: 5,
textAlign: "center"
}
}
]
描述:
1.好像只在wx.,request中success才遇到,也就是e,data的值不能赋值给success函数之外定义的值,外面的值接收不到!!!
2.wx.getLovation中e好像赋值给外面的值可以接收到。
3.在onLoad()初始化函数中先执行赋值,输出等简单的操作才会执行wx.getLocation,wx.request之类的函数。