简体   繁体   English

Google Nodejs 上的操作 getDeviceLocation

[英]Actions on Google Nodejs getDeviceLocation

I'm working on learning Dialogflow with Google Actions and I'm a bit lost with thew new v2 actions-on-google.我正在使用 Google Actions 学习 Dialogflow,但我对新的 v2 actions-on-google 有点迷茫。

I'm attempting to get a device location, however the method I thought was correct is returning undefined.我正在尝试获取设备位置,但是我认为正确的方法返回未定义。

I feel like I'm missing something simple but I haven't been able to find it.我觉得我错过了一些简单的东西,但我一直找不到。

The code is:代码是:

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.');
  }
});

I don't think you'd want any method on app , even if that one existed, since app is available for all Intent Handler calls.我认为您不希望app上有任何方法,即使该方法存在,因为app可用于所有 Intent Handler 调用。 Information specific to that conversation is in the conv parameter passed to the Intent Handler.特定于该对话的信息位于传递给意图处理程序的conv参数中。

You probably want something more like你可能想要更像

const coordinates = conv.device.location;

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

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