我已经成功地要求用户获取其粗设备的权限,并且在用户允许权限后检查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
}
答案 0 :(得分:0)
我最后用app.SupportedPermissions.DEVICE_PRECISE_LOCATION
对它进行了测试,这对我的坐标没问题。我希望谷歌修复粗略位置的错误,如果有的话。