开发了一个微信公众号网页,其中有导航的功能需要跳转到高德导航APP进行导航,在浏览器里可以唤起,但是在微信内无法唤起,请问是有什么限制吗,如果有限制的情况下 是否有其他解决方案呢
const handleNavigate = () => {
// 定义经纬度
const latitude = 34.24;
const longitude = 111.11;
// 获取用户代理判断设备类型
const userAgent = navigator.userAgent.toLowerCase();
const isIOS = /iphone|ipad|ipod/.test(userAgent);
const isAndroid = userAgent.indexOf('android') > -1;
// 构建高德导航URL scheme
let mapUrl = '';
if (isIOS) {
// iOS高德地图URL scheme
mapUrl = `iosamap://navi?sourceApplication=appName&lat=${latitude}&lon=${longitude}&dev=0&style=2`;
} else if (isAndroid) {
// Android高德地图URL scheme
mapUrl = `androidamap://navi?sourceApplication=appName&lat=${latitude}&lon=${longitude}&dev=0&style=2`;
} else {
// 其他设备fallback到web版
mapUrl = `https://uri.amap.com/navigation?to=${longitude},${latitude},目的地&mode=car&callnative=1`;
}
// 尝试打开原生应用
window.location.href = mapUrl;
// 设置一个超时,如果没能成功唤起应用,显示提示
const timeout = setTimeout(() => {
// 如果页面仍然存在(没有跳转成功),则提示用户
uni.showModal({
title: '打开失败',
content: '未能打开高德地图应用,请确保已安装高德地图或手动打开并输入坐标进行导航',
confirmText: '复制坐标',
success: (res) => {
if (res.confirm) {
uni.setClipboardData({
data: `${longitude},${latitude}`,
success: function () {
uni.showToast({
title: '坐标已复制',
icon: 'none'
});
}
});
}
}
});
}, 2000);
// 如果页面隐藏了(说明跳转成功),清除超时
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
clearTimeout(timeout);
}
});
}
可以试下判断微信环境 唤起高德的h5(高德h5地址需要你去看下他们的拼接格式,我这里随便找了个),高德的h5再唤起高德App。
https://m.amap.com/poi/detail?__p=B023B0A9F4%2C30.381619721339057%2C119.78026628494261%2C%E5%BE%84%E5%B1%B1%E5%8F%A4%E9%81%93%2C%E5%BE%84%E5%B1%B1%E9%95%87%E5%BE%84%E5%B1%B1%E6%9D%91%E6%A1%90%E6%A1%A557%E5%8F%B7&src=app_share&userRelationToken=c1609748f4dc11efa47b00163e2ff4eb1&share_type=url&share_from=poi_poi&share_from_type=AJX&share_bizParams=%7B%22poiid%22%3A%22B023B0A9F4%22%2C%22name%22%3A%22%E5%BE%84%E5%B1%B1%E5%8F%A4%E9%81%93%22%2C%22address%22%3A%22%E5%BE%84%E5%B1%B1%E9%95%87%E5%BE%84%E5%B1%B1%E6%9D%91%E6%A1%90%E6%A1%A557%E5%8F%B7%22%2C%22new_type%22%3A%22110200%22%2C%22atag_cid%22%3A%22621024%3B621047%3B621049%7C621024%3B621025%22%2C%22x%22%3A223532368%2C%22y%22%3A110420602%2C%22lon%22%3A%22119.780266%22%2C%22lat%22%3A%2230.381620%22%2C%22trigger%22%3A%22click%22%7D&share_lastClickSpm=amap.27854080.share.share_entrance&share_bid=olkp1cnimnfsfflfc3dei5mnn17edds5d763eeb&poiid=B023B0A9F4
需要在微信开放平台,绑定你的域名和移动应用才能跳转,不绑定跳转不了。