我已成功请求用户获得其粗糙设备的许可,并且我已检查 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
}
最佳答案
我最终使用 app.SupportedPermissions.DEVICE_PRECISE_LOCATION
进行了测试,结果显示我的坐标没有问题。我希望 Google 修复粗略位置的错误(如果有的话)。
关于node.js - app.getDeviceLocation() 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44640782/