调用:
//打开导航
openMap({ //客户当前地址
lon: _this.user_lng,
lat: _this.user_lat,
name: '起点'
},{ //店铺地址
lon: _this.shop_lng,
lat: _this.shop_lat,
name: '终点'
});
/***打开外部地图APP
@param {Object} start 起点信息(start.lon: 经度 start.lat: 维度 start.name: 位置信息)
@param {Object} start 终点信息(end.lon: 经度 end.lat: 维度 end.name: 位置信息)
*/
function openMap(start = {}, end = {}){
console.log(JSON.stringify(start));
var navigator = api.require('navigator');
if (api.systemType == 'android')
{
navigator.installed({ //判断用户是否安装百度地图
target: 'bMap'
}, function(ret, err) {
if (ret.status)
{
console.log("已安装百度地图"+JSON.stringify(ret));
navigator.bMapNavigation({ //打开百度地图APP
start: { // 起点信息.
lon: start.lon, // 经度.
lat: start.lat, // 纬度.
name: start.name //地址
},
end: { // 终点信息.
lon: end.lon, // 经度.
lat: end.lat, // 纬度.
name: end.name //地址
},
mode: 'driving'
});
}
else
{
console.log("未安装百度地图"+JSON.stringify(err));
// cui.confirm({
// title: "提示",
// content: "检测到您的手机尚未安装百度地图客户端,是否去安装",
// mask: true,
// maskTouch: true,
// btns: [{name: '取消'}, {name: '确定'}],
// },function(e){
// if(e.index == 1){
// var url = "http://map.baidu.com/zt/client/index/";
// // var url = "http://map.baidu.com/zt/qudao/newfengchao/1012337a/html/slide.html";
// openWin('web_page','../home/web_page.html',{'url': url, "title": "返回"});
// }
// });
// return false;
navigator.installed({ //判断用户是否安装高德地图APP
target: 'aMap'
}, function(ret, err) {
if (ret.status)
{
console.log("已安装高德地图"+JSON.stringify(ret));
navigator.aMapNavigation({
start: { // 起点信息.
lon: start.lon, // 经度.
lat: start.lat, // 纬度.
name: start.name //地址
},
end: { // 终点信息.
lon: end.lon, // 经度.
lat: end.lat, // 纬度.
name: end.name //地址
},
dev: 0,
strategy: 'fast'
});
}
else
{
console.log("未安装高德地图"+JSON.stringify(err));
cui.confirm({
title: "提示",
content: "检测到您的手机尚未安装百度地图客户端,是否去安装",
mask: true,
maskTouch: true,
btns: [{name: '取消'}, {name: '确定'}],
},function(e){
if(e.index == 1){
var url = "http://map.baidu.com/zt/client/index/";
// var url = "http://map.baidu.com/zt/qudao/newfengchao/1012337a/html/slide.html";
openWin('web_page','../home/web_page.html',{'url': url, "title": "返回"});
}
});
}
});
}
});
}
else
{ //ios打开自带地图导航
navigator.appleNavigation({
start: { // 起点信息.
lon: start.lon, // 经度.
lat: start.lat, // 纬度.
name: start.name //地址
},
end: { // 终点信息.
lon: end.lon, // 经度.
lat: end.lat, // 纬度.
name: end.name //地址
},
mode: 'driving'
});
}
}