嗨,我遇到一个问题,当我使用相同的dialogflow帐户在google mini设备上进行测试时,无法获得设备的粗略位置。我可以获取用户名,但不能获得设备位置。我对此感到沮丧。请帮助解决此问题。
这是我的代码,
const express = require('express');
const bodyParser = require('body-parser');
const {dialogflow,Permission} = require('actions-on-google');
const app = dialogflow({
clientId : 'xyz'
});
app.intent('Default Welcome Intent', conv => {
const options = {
context: 'To locate you',
permissions: ['NAME','DEVICE_COARSE_LOCATION'],
};
conv.ask(new Permission(options));
});
app.intent('User_info',(conv, params, permissionGranted) => {
console.log(conv);
var location=conv.device.location;
console.log(location);
if(permissionGranted){
const name = conv.user.name;
console.log(name);
var resp="you are located at"+conv.device.location.city;
conv.ask(resp);
}else{
conv.close("sorry I'm unable to locate you right now. Okay bye now");
}
});
const expressApp=express().use(bodyParser.json())
expressApp.post('/',app);
expressApp.listen(3000);
答案 0 :(得分:0)
我刚刚测试了DEVICE_COARSE_LOCATION权限,并在我希望查看其位置的Firebase日志中找到了一个空对象。
您是否尝试过使用DEVICE_PRECISE_LOCATION?这是一个工作原理示例:
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: ['NAME', 'DEVICE_PRECISE_LOCATION']
}));
});
// Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
// agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
if (!permissionGranted) {
conv.ask(`Ok, no worries. What's your favorite color?`);
conv.ask(new Suggestions('Blue', 'Red', 'Green'));
} else {
console.log(conv);
conv.data.userName = conv.user.name.given;
conv.data.userLatitude = conv.device.location.coordinates.latitude;
conv.data.userLongitude = conv.device.location.coordinates.longitude;
conv.ask(`Thanks, ${conv.data.userName} at latitude ${conv.data.userLatitude} and longitude ${conv.data.userLongitude}. What's your favorite color?`);
}
});