jonnycraze
jonnycraze

Reputation: 498

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.

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

Upvotes: 1

Views: 87

Answers (1)

Prisoner
Prisoner

Reputation: 50741

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. Information specific to that conversation is in the conv parameter passed to the Intent Handler.

You probably want something more like

const coordinates = conv.device.location;

Upvotes: 1

Related Questions