import gcoord from "gcoord"; import { getCoord } from "@/utils/LonLatConvert.js" // gaode // ‌天地图使用的坐标系是CGCS2000(中国大地坐标系统2000) export const openMap = (parmas = {}) => { const { name, code, type, info: { longitude, latitude } } = parmas; // console.log("name, code, type = ", name, code, type, longitude, latitude) uni.showLoading() getCoord({ name, code, type, longitude, latitude }).then(res => { const { lng, lat } = res; openApp({ lng, lat, type, name }) }) // getCoord({ name, code , type longitude, latitude}).then(res => { // const { lng, lat } = res; // openApp({ lng, lat , type , name }) // }).catch(err => { // uni.hideLoading() // uni.showToast({ // title: '打开导航失败', // icon: "none" // }) // }) } const openApp = (parmas = {}) => { const { lng, lat, type, name } = parmas; let url; switch (type) { case 'baidu': url = `baidumap://map/marker?location=${lat},${lat}&title=${encodeURIComponent(name)}&content=${encodeURIComponent(name)}&src=webapp`; break; case 'gaode': url = `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(name)}&src=mypage&coordinate=gaode&callnative=0`; break; case 'tencent': url = `qqmap://map/rgeo?location=${lat},${lat}&name=${encodeURIComponent(name)}&coord_type=1&policy=0`; break; default: console.error('不支持的地图类型'); return; } uni.hideLoading() if (url) { window.location.href = url } // // 使用iframe打开URL Scheme, 避免直接跳转导致页面卡死 // const iframe = document.createElement('iframe'); // iframe.style.display = 'none'; // iframe.src = url; // document.body.appendChild(iframe); // setTimeout(() => { // document.body.removeChild(iframe); // }, 1000); // // 定时器检测是否唤起成功,如果失败则跳转到网页版地图 // let timer = setTimeout(() => { // window.location.href = // `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(name)}&src=mypage&coordinate=gaode&callnative=0`; // 默认跳转高德网页版 // }, 2000); // window.addEventListener('blur', () => { // clearTimeout(timer) // }); }