app.getDeviceLocation() 总是返回 null
app.getDeviceLocation() always returning null
我已成功请求用户获得他们的粗糙设备的许可,并且我已检查 app.isPermissionGranted()
在用户允许许可后从 false 转换为 true,但是每当我使用 app.getDeviceLocation()
时,它只是 returns null
。当我询问时,我测试的 Google 家给出了正确的位置,"Where am I?"
这是我的代码片段:
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 修复粗略位置的错误。
我已成功请求用户获得他们的粗糙设备的许可,并且我已检查 app.isPermissionGranted()
在用户允许许可后从 false 转换为 true,但是每当我使用 app.getDeviceLocation()
时,它只是 returns null
。当我询问时,我测试的 Google 家给出了正确的位置,"Where am I?"
这是我的代码片段:
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 修复粗略位置的错误。