Google 节点 J 上的操作获取设备位置
Actions on Google Nodejs getDeviceLocation
我正在学习使用 Google Actions 的 Dialogflow,我对新的 v2 actions-on-google.
有点不知所措
我正在尝试获取设备位置,但我认为正确的方法返回未定义。
我觉得我遗漏了一些简单的东西,但我一直没能找到它。
密码是:
const functions = require('firebase- functions');
const { dialogflow, Permission } = require('actions-on-google');
const app = dialogflow();
app.intent('create_log', conv => {
conv.ask(new Permission({
context: 'To locate you',
permissions: 'DEVICE_PRECISE_LOCATION'
}));
});
app.intent('user_info', (conv, params, granted) => {
if (granted) {
const coordinates = app.getDeviceLocation().coordinates;
if (coordinates) {
conv.close(`You are at ${coordinates}`);
} else {
// Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates
// and a geocoded coordinates on voice-activated speakers.
// Coarse location only works on voice-activated speakers.`enter code here`
conv.close('Sorry, I could not figure out where you are.');
}
} else {
conv.close('Sorry, I could not figure out where you are.');
}
});
我认为您不需要 app
上的任何方法,即使该方法存在,因为 app
可用于所有 Intent Handler 调用。该对话的特定信息位于传递给 Intent Handler 的 conv
参数中。
您可能想要更像
的东西
const coordinates = conv.device.location;
我正在学习使用 Google Actions 的 Dialogflow,我对新的 v2 actions-on-google.
有点不知所措我正在尝试获取设备位置,但我认为正确的方法返回未定义。
我觉得我遗漏了一些简单的东西,但我一直没能找到它。
密码是:
const functions = require('firebase- functions');
const { dialogflow, Permission } = require('actions-on-google');
const app = dialogflow();
app.intent('create_log', conv => {
conv.ask(new Permission({
context: 'To locate you',
permissions: 'DEVICE_PRECISE_LOCATION'
}));
});
app.intent('user_info', (conv, params, granted) => {
if (granted) {
const coordinates = app.getDeviceLocation().coordinates;
if (coordinates) {
conv.close(`You are at ${coordinates}`);
} else {
// Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates
// and a geocoded coordinates on voice-activated speakers.
// Coarse location only works on voice-activated speakers.`enter code here`
conv.close('Sorry, I could not figure out where you are.');
}
} else {
conv.close('Sorry, I could not figure out where you are.');
}
});
我认为您不需要 app
上的任何方法,即使该方法存在,因为 app
可用于所有 Intent Handler 调用。该对话的特定信息位于传递给 Intent Handler 的 conv
参数中。
您可能想要更像
的东西const coordinates = conv.device.location;