openApp.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import gcoord from "gcoord";
  2. import { getCoord } from "@/utils/LonLatConvert.js"
  3. export const MapTypeList = [
  4. {
  5. label:'高德地图',
  6. value:'gaode'
  7. },
  8. {
  9. label:'百度地图',
  10. value:'baidu'
  11. }
  12. ]
  13. // ‌天地图使用的坐标系是CGCS2000(中国大地坐标系统2000)
  14. export const openMap = (parmas = {}) => {
  15. const { name, code, type, info: { longitude, latitude , locationName } } = parmas;
  16. // console.log("name, code, type = ", name, code, type, longitude, latitude)
  17. uni.showLoading()
  18. getCoord({ name, code, type, longitude, latitude }).then(res => {
  19. const { lng, lat } = res;
  20. openApp({ lng, lat, type, name , locationName})
  21. })
  22. }
  23. const openApp = (parmas = {}) => {
  24. const { lng, lat, type, name , locationName} = parmas;
  25. let url;
  26. switch (type) {
  27. case 'baidu':
  28. url = `http://api.map.baidu.com/marker?location=${lat},${lng}&title=${encodeURIComponent(locationName)}&content=${encodeURIComponent(name)}&output=html&src=webapp.baidu.openAPIdemo`
  29. break;
  30. case 'gaode':
  31. url =
  32. `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(name)}&src=mypage&coordinate=gaode&callnative=0`;
  33. break;
  34. case 'tencent':
  35. url =
  36. `qqmap://map/rgeo?location=${lat},${lat}&name=${encodeURIComponent(name)}&coord_type=1&policy=0`;
  37. break;
  38. default:
  39. console.error('不支持的地图类型');
  40. return;
  41. }
  42. uni.hideLoading()
  43. if (url) {
  44. window.location.href = url
  45. }
  46. // // 使用iframe打开URL Scheme, 避免直接跳转导致页面卡死
  47. // const iframe = document.createElement('iframe');
  48. // iframe.style.display = 'none';
  49. // iframe.src = url;
  50. // document.body.appendChild(iframe);
  51. // setTimeout(() => {
  52. // document.body.removeChild(iframe);
  53. // }, 1000);
  54. // // 定时器检测是否唤起成功,如果失败则跳转到网页版地图
  55. // let timer = setTimeout(() => {
  56. // window.location.href =
  57. // `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(name)}&src=mypage&coordinate=gaode&callnative=0`; // 默认跳转高德网页版
  58. // }, 2000);
  59. // window.addEventListener('blur', () => {
  60. // clearTimeout(timer)
  61. // });
  62. }