app.getDeviceLocation()始终返回null

时间:2017-06-19 22:13:59

标签: node.js actions-on-google

我已经成功地要求用户获取其粗设备的权限,并且在用户允许权限后检查app.isPermissionGranted()从false转换为true,但每当我使用app.getDeviceLocation()时,它只返回null。我测试的Google Home在我询问时给出了正确的位置,"我在哪里?"

这是我的代码片段:

    function askDate(app) {
            console.log('Permission:', app.isPermissionGranted()); //says true
            if (app.isPermissionGranted()) {
                //this always says null
                console.log('User device location:', JSON.stringify(app.getDeviceLocation())); 
                app.ask('thanks for the location!');
            } else {
                app.tell('You need to allow me to access your location to give an accurate recommendation');
            }
        }

function askForLocPermission(app) {
            console.log('Permission:', app.isPermissionGranted()); //says false
            let permission = app.SupportedPermissions.DEVICE_COARSE_LOCATION;
            app.data.permission = permission;
            app.askForPermission('To get weather near you', permission); //asks user for permission to get their zip code
        }

1 个答案:

答案 0 :(得分:0)

我最后用app.SupportedPermissions.DEVICE_PRECISE_LOCATION对它进行了测试,这对我的坐标没问题。我希望谷歌修复粗略位置的错误,如果有的话。