收藏
回答

公众号网页开发,如何在本地调试中调用wx.config接口?并使用wx.getLoaction方法?

如何在本地调试中调用wx.config接口?并使用wx.getLoaction方法?

最后一次编辑于  02-28
回答关注问题邀请回答
收藏

3 个回答

  • 余生.
    余生.
    02-28
    getLocation() {
    	let that = this;
    	wx.showLoading({
    		title: '正在获取当前位置...',
    		mask: true,
    	});
    
    
    	wx.getLocation({
    		type: 'wgs84', // 坐标类型
    		success: (res) => {
    			console.log('位置信息', res);
    			const {
    				latitude,
    				longitude
    			} = res;
    			this.setData({
    				location: {
    					latitude,
    					longitude
    				}, // 更新页面数据
    			});
    			wx.showToast({
    				title: '位置获取成功',
    				icon: 'success',
    			});
    			wx.hideLoading();
    		},
    		fail: (err) => {
    			console.error('获取位置失败', err);
    			wx.showToast({
    				title: '无法获取位置,请检查权限或网络',
    				icon: 'none',
    			});
    
    
    			// 如果用户拒绝授权,引导用户开启权限
    			wx.getSetting({
    				success(res) {
    					if (!res.authSetting['scope.userLocation']) {
    						wx.showModal({
    							title: '授权提示',
    							content: '定位失败,是否开启定位权限?',
    							confirmText: '去开启',
    							success(modalRes) {
    								if (modalRes.confirm) {
    									wx.openSetting({
    										success() {
    											// 重新发起定位
    											that.getLocation();
    										},
    									});
    								}
    							},
    						});
    					}
    				},
    			});
    		},
    	});
    },
    
    02-28
    有用
    回复
  • 那一抹微笑😊穿透阳光
    那一抹微笑😊穿透阳光
    02-28

    小程序不需要调用wx.config,如果是h5,你可以在开发工具上切换开发模式,选择公众号网页调试

    02-28
    有用
    回复
  • 智能回答 智能回答 该问答由AI生成
    02-28
    有用
登录 后发表内容