| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /**
- * 地图导航页面
- * H5 通过 wx.miniProgram.navigateTo 跳转到此页面
- * 参数: latitude, longitude, name, address
- * 示例: wx.miniProgram.navigateTo({url: '/common-page/pages/map-open/index?latitude=39.908&longitude=116.397&name=天安门&address=北京市东城区'})
- */
- Page({
- data: {},
- onLoad: function (options) {
- const { latitude, longitude, name, address } = options;
- if (!latitude || !longitude) {
- wx.showToast({
- title: '缺少位置信息',
- icon: 'none'
- });
- setTimeout(() => {
- wx.navigateBack();
- }, 1500);
- return;
- }
- // 直接打开地图导航
- wx.openLocation({
- latitude: parseFloat(latitude),
- longitude: parseFloat(longitude),
- name: decodeURIComponent(name || ''),
- address: decodeURIComponent(address || ''),
- scale: 18,
- success: () => {
- console.log('✅ 地图打开成功');
- },
- fail: (err) => {
- console.error('❌ 打开地图失败:', err);
- wx.showToast({
- title: '打开地图失败',
- icon: 'none'
- });
- },
- complete: () => {
- // 打开地图后返回上一页
- wx.navigateBack();
- }
- });
- }
- });
|