收藏
回答

使用h5开发公众号用 wx.getLocation报config:fail,invalidsign?

wx.config({
        debug: false,
        appId: '${appId}',   // 固定的 appId
        timestamp: '${timestamp}',
        nonceStr: '${nonceStr}',
        signature: '${signature}',
        jsApiList: ['checkJsApi','openLocation','getLocation']
    });
    // 获取当前位置,优先使用微信定位,其次高德地图定位,最后使用浏览器定位
    AMap.plugin('AMap.Geolocation', function () {
        
        var geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,
            timeout: 10000,
            position: 'RB',
            extensions: 'all',
            convert: true
        });
        wx.ready(function () {
        	wx.checkJsApi({
				jsApiList: ['getLocation'],
				success: function (res) if(res.checkResult.getLocation){
						wx.getLocation({
						    success: function (res) {
						        latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
						        longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
						        layer.closeAll();
								},
							cancel: function(){
								layer.closeAll();
							}
						});
					}
				}
			});
		}); 
            wx.getLocation({
                type: 'wgs84',
                success: function (res) {
                    console.log('微信定位成功:', res);
                    onComplete({
                        position: [res.longitude, res.latitude],
                        addressComponent: {
                            province: '微信省',
                            city: '微信市',
                            district: '微信区',
                            street: '微信路',
                            streetNumber: '88号'
                        }
                    });
                },
                fail: function () {
                    console.error('微信定位失败,尝试高德定位...');
                    geolocation.getCurrentPosition((status, result) => {
                        if (status === 'complete') {
                            onComplete(result);
                        } else {
                            onError(result);
                        }
                    });
                }
            });
        });这是我的代码
回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    18小时前

    后端问题,前端代码没啥看的

    18小时前
    有用
    回复
登录 后发表内容