繁体   English   中英

Google Nodejs 上的操作 getDeviceLocation

[英]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 调用。 特定于该对话的信息位于传递给意图处理程序的conv参数中。

你可能想要更像

const coordinates = conv.device.location;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM