index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * 地图导航页面
  3. * H5 通过 wx.miniProgram.navigateTo 跳转到此页面
  4. * 参数: latitude, longitude, name, address
  5. * 示例: wx.miniProgram.navigateTo({url: '/common-page/pages/map-open/index?latitude=39.908&longitude=116.397&name=天安门&address=北京市东城区'})
  6. */
  7. Page({
  8. data: {},
  9. onLoad: function (options) {
  10. const { latitude, longitude, name, address } = options;
  11. if (!latitude || !longitude) {
  12. wx.showToast({
  13. title: '缺少位置信息',
  14. icon: 'none'
  15. });
  16. setTimeout(() => {
  17. wx.navigateBack();
  18. }, 1500);
  19. return;
  20. }
  21. // 直接打开地图导航
  22. wx.openLocation({
  23. latitude: parseFloat(latitude),
  24. longitude: parseFloat(longitude),
  25. name: decodeURIComponent(name || ''),
  26. address: decodeURIComponent(address || ''),
  27. scale: 18,
  28. success: () => {
  29. console.log('✅ 地图打开成功');
  30. },
  31. fail: (err) => {
  32. console.error('❌ 打开地图失败:', err);
  33. wx.showToast({
  34. title: '打开地图失败',
  35. icon: 'none'
  36. });
  37. },
  38. complete: () => {
  39. // 打开地图后返回上一页
  40. wx.navigateBack();
  41. }
  42. });
  43. }
  44. });