H5唤醒手机app地图
uni.showActionSheet({
title: '请选择系统中已安装的地图应用导航',
itemList: ['腾讯地图', '百度地图', '高德地图'],
success: function (res) {
console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
switch(res.tapIndex){
case 0:
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
case 1:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
break;
case 2:
if(!userAgent.includes('Android')){
url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
}else{
url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
}
break;
default:
break;
}
if(url){
url = encodeURI(url)
window.location.href = url;
}
},
fail: function (res) {
console.log(res.errMsg);
}
});
APP-PLUS唤醒手机地图app
if (plus.os.name == "Android") {
plus.nativeUI.actionSheet({
title: "选择地图应用",
cancel: "取消",
buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
}, function(e) {
switch (e.index) {
case 1:
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=${name}`;
break;
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
break;
case 3:
url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("本机未安装指定的地图应用");
});
}
})
} else {
plus.nativeUI.actionSheet({
title: "选择地图应用",
cancel: "取消",
buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
}, function(e) {
switch (e.index) {
case 1:
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=${name}`;
break;
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
break;
case 3:
url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("本机未安装指定的地图应用");
});
}
})
}
微信小程序
viewMapLocation(longitude, latitude, address) {
latitude = Number(latitude);
longitude = Number(longitude);
uni.getLocation({
type: 'wgs84',
success: function(res) {
console.log(res, '经纬度')
if (res.errMsg == "getLocation:ok") {
console.log(latitude)
console.log(longitude)
uni.openLocation({
latitude: latitude,
longitude: longitude,
address: address,
scale: 18,
success: function() {
console.log('success');
}
});
}
},
fail: function(res) {
console.log(res)
if (res.errMsg == "getLocation:fail auth deny") {
uni.showModal({
content: '检测到您没打开获取信息功能权限,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
console.log('确定');
}
})
} else {
console.log('取消');
return false;
}
}
})
}
}
});
},