index.wxml:
<map id=“map” latitude="{{latitude}}" longitude="{{longitude}}" markers="{{markers}}" bindmarkertap=“markertap” polyline="{{polyline}}" scale=“14” show-location style=“width: 100%; height:30vh ;”>
index.js
onReady:function(){
var that = this
console.log(‘onready’)
wx.request({
url: ‘http://111.207.49.73:10080/yvirtualkey-wechat-gateway/mobile/wechat/vehicle/listget’,
data: {
“messageheader”: {
“timestamp”: “20171024094720”,
“appkey”: “yesway123”,
“version”: “1.0”
}
},
header: {
‘content-type’: ‘application/json’
}, method: “POST”,
success: function (res) {
console.log(res.data)
}
})
wx.openSetting({
success: (res) => {
console.log(“授权结果…”)
wx.request({
url: ‘http://111.207.49.73:10080/yvirtualkey-wechat-gateway/mobile/wechat/vehicle/listget’,
data: {
“messageheader”: {
“timestamp”: “20171024094720”,
“appkey”: “yesway123”,
“version”: “1.0”
}
},
header: {
‘content-type’: ‘application/json’
}, method: “POST”,
success: function (res) {
console.log(res.data)
var json = res.data.data.list;
var ymarker = []
for (var i = 0; i < json.length; i++) {
var carvalue = {};
var item = json[i];
carvalue.id = i;
carvalue.latitude = item.latitude//item.latitude;
carvalue.longitude = item.longitude//item.longitude;
carvalue.iconPath = ‘…/image/car.png’;
carvalue.width = 25;
carvalue.height = 35;
ymarker.push(carvalue)
}
that.setData({
markers: ymarker
})
console.log(that.data.markers)
}
});
wx.getLocation({
type:‘gcj02’,
success: function (res) {
console.log(res.latitude + “ada” + res.longitude);
that.setData({
latitude: res.latitude,
longitude: res.longitude,
covers:[{
latitude: res.latitude,
longitude: res.longitude,
iconPath: ‘…/image/location.png’
}]
})
console.log(that.data.markers)
}
})
}
})
}