|
function androidAddLocation(waybillInfo) {
console.log(nowWayBillCount)
if (nowWayBillCount == 0) {
aMap.stopLocation();
reutrn;
}
// 获取手机号
var iphone = $api.getStorage('mobile');
var addInfo = waybillInfo;
// //console.log("定位返回数据1:", JSON.stringify(ret));
// 安卓通知工具,可用于创建安卓通知8.0以及以后版本通知通道创建
var notificationUtil = api.require('notificationUtil');
// 创建通知通道
notificationUtil.creatChannel({
Id: msgId,
name: msgName,
description: msgDescription
}, function (ret, err) {
if (ret && ret.status) {
// 获取定位
aMap.getLocation(
{
autoStop: false, //获取到位置信息后是否自动停止定位
enableLocInForeground: true,//后台定位
notification: { //通知栏的提示
title: msgName,//标题; 默认值:应用名称
content: msgDescription,//内容; 默认值:正在后台运行
channelId: msgId//通知通道号,argetSdkVersion大于等于28时必填
}
},
function (ret, err) {
// console.log("定位返回数据2:", JSON.stringify(ret));
if (ret.status) {
addInfo.longitude = ret.lon;
addInfo.latitude = ret.lat;
// 根据经纬度查找地址信息,
aMap.getNameFromCoords({
lon: ret.lon,
lat: ret.lat
}, function (ret, err) {
// 获取上一次定位时间
var lastTime = localStorage.getItem("iosLastLocation");
//localStorage.setItem("iosLastLocation", timestamp);
if (lastTime == null) {
// 存入定位时间
localStorage.setItem("iosLastLocation", new Date());
}
else {
// 定位时间间隔
var cz = calcTime(lastTime, new Date());
if (cz < timeSpan) {
return
}
else {
localStorage.setItem("iosLastLocation", new Date());
}
}
if (ret.status) {
addInfo.positionAddress = ret.address;
// 高德经纬度转百度经纬度
var dw = gps_bgps(addInfo.longitude, addInfo.latitude)
// 上传定位
dealData("driver/transport/reportLocation?mobile=" + iphone + "&lng=" + dw.bd_lng + "&lat=" + dw.bd_lat, 'GET', {}, function (res) {
console.log("定位返回数据:", JSON.stringify(res));
if (res) {
//添加定位
//addLocation(waybillInfo);
} else {
$.mvalidateTip(res.message);
}
setTimeout('api.refreshHeaderLoadDone()', '500');
},
function (err) {
api.toast({
msg: '定位数据推送失败,请检查网络',
duration: 5000,
location: 'middle'
});
}
)
} else {
api.toast({
msg: '定位数据解析失败,为获取到有效位置',
duration: 5000,
location: 'middle'
});
}
});
}
else {
errorCount++;
if (errorCount > tipsCount) {
return;
}
//console.log("定位返回err:", JSON.stringify(err));
if (err && err.locationDetail) {
var errmsg = err.locationDetail;
if (errmsg.indexOf("#1201")) {
errmsg = errmsg + "\r\n请选择[始终允许]";
}
//alert(err.locationDetail + new Date());
//$.mvalidateTip(err.locationDetail + new Date());
api.toast({
msg: errmsg,
duration: 5000,
location: 'middle'
});
}
else {
api.toast({
msg: '定位失败,定位信号弱',
duration: 5000,
location: 'middle'
});
//alert('定位失败,定位信号弱' + new Date());
//$.mvalidateTip('定位失败,定位信号弱' + new Date());
}
}
});
}
else {
api.toast({
msg: '后台运行定位失败,请检查权限',
duration: 5000,
location: 'middle'
});
}
})
} |
|