import gcoord from "gcoord"; import { getCoord } from "@/utils/LonLatConvert.js" export const MapTypeList = [ { label:'高德地图', value:'gaode' }, { label:'百度地图', value:'baidu' } ] // ‌天地图使用的坐标系是CGCS2000(中国大地坐标系统2000) export const openMap = (parmas = {}) => { const { name, code, type, info: { longitude, latitude , locationName } } = 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 , locationName}) }) } const openApp = (parmas = {}) => { const { lng, lat, type, name , locationName} = parmas; let url; switch (type) { case 'baidu': url = `http://api.map.baidu.com/marker?location=${lat},${lng}&title=${encodeURIComponent(locationName)}&content=${encodeURIComponent(name)}&output=html&src=webapp.baidu.openAPIdemo` 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) // }); }