var amapFile = require(../../libs/amap-wx.js);
var config = require(../../libs/config.js);
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
markers: [{
iconPath: "../../img/mapicon_navi_s.png",
id: 0,
latitude: 39.989643,
longitude: 116.481028,
width: 23,
height: 33
},{
iconPath: "../../img/mapicon_navi_e.png",
id: 0,
latitude: 39.90816,
longitude: 116.434446,
width: 24,
height: 34
}],
distance: ,
cost: ,
state: 0,
method:[驾车,公交,骑行,步行],
index:0,
TabCur:0,
polyline: [],
transits: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var that = this;
wx.showLoading({
title: "定位中",
mask: true
})
wx.getLocation({
type: gcj02,
altitude: true, //高精度定位
success: function(res) {
console.info(res);
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
that.setData({
markers: [{
name: 当前位置,
latitude: latitude,
longitude: longitude
}, {
name: 您要去哪儿?,
latitude: ,
longitude:
}]
})
},
fail: function() {
wx.showToast({
title: "定位失败",
icon: "none"
})
},
complete: function() {
wx.hideLoading()
}
})
},
//选择器改变函数
tabSelect(e) {
this.setData({
TabCur: e.currentTarget.dataset.id,
scrollLeft: (e.currentTarget.dataset.id - 1) * 60
})
},
//获取出发地
getFormAddress: function() {
var that = this;
wx.chooseLocation({
success: function(res) {
var name = res.name
var address = res.address
var latitude = res.latitude
var longitude = res.longitude
var markesName = "markers[" + 0 + "].name";
var markesLatitude = "markers[" + 0 + "].latitude";
var markeslongitude = "markers[" + 0 + "].longitude";
var markesiconPath = "markers[" + 0 + "].iconPath";
that.setData({
[markesName]: name,
[markesLatitude]: latitude,
[markeslongitude]: longitude,
[markesiconPath]: "../../img/mapicon_navi_s.png"
})
},
fail: function() {
wx.showToast({
title: 定位失败,
icon: "none"
})
},
complete: function() {
//隐藏定位中信息进度
wx.hideLoading()
}
})
},
//获取目的地
getToAddress: function() {
var that = this;
wx.chooseLocation({
success: function(res) {
console.log(res);
var name = res.name
var address = res.address
var latitude = res.latitude
var longitude = res.longitude
var markesName = "markers[" + 1 + "].name";
var markesLatitude = "markers[" + 1 + "].latitude";
var markeslongitude = "markers[" + 1 + "].longitude";
var markesiconPath = "markers[" + 1 + "].iconPath";
that.setData({
[markesName]: name,
[markesLatitude]: latitude,
[markeslongitude]: longitude,
[markesiconPath]: "../../img/mapicon_navi_e.png"
})
},
fail: function() {
wx.showToast({
title: 定位失败,
icon: "none"
})
},
complete: function() {
//隐藏定位中信息进度
wx.hideLoading()
}
})
},
/**
* 确定
*/
getSure: function() {
var that = this;
var origin = that.data.markers[0].longitude + , + that.data.markers[0].latitude;//出发地
var destination = that.data.markers[1].longitude + , + that.data.markers[1].latitude; //目的地
var TabCur=this.data.TabCur;
app.origin = origin;
app.destination = destination;
var key = config.Config.key;
var myAmapFun = new amapFile.AMapWX({
key: key
});
if(TabCur==0){
myAmapFun.getDrivingRoute({//获取驾车路线
origin: origin,
destination: destination,
success: function(data) {
var points = [];
if (data.paths && data.paths[0] && data.paths[0].steps) {
var steps = data.paths[0].steps;
for (var i = 0; i < steps.length; i++) {
var poLen = steps[i].polyline.split(;);
for (var j = 0; j < poLen.length; j++) {
points.push({
longitude: parseFloat(poLen[j].split(,)[0]),
latitude: parseFloat(poLen[j].split(,)[1])
})
}
}
}
that.setData({//将路线在地图上画出来
state: 1,
polyline: [{
points: points,
color: "#0091ff",
width: 6
}]
});
if (data.paths[0] && data.paths[0].distance) {
that.setData({
distance: data.paths[0].distance + 米
});
}
if (data.taxi_cost) {
that.setData({
cost: 打车约 + parseInt(data.taxi_cost) + 元
});
}
}
})
}
},
/**
* 详情页
*/
goDetail: function() {
var TabCur=this.data.TabCur;
if(TabCur==0){
wx.navigateTo({
url: ../detail/detail
})
}
},
})
暂时没有评论,来抢沙发吧~