I want to book an ambulance while having conversation with user via google assistant.I have to get the distance between the pickup point and destination point to calculate fare as per the kms.
I have the user's location in longitudes and latitudes. and the destination location as a address(Fortis Hospital at Bhoiwada, Kalyan). How do I calculate the distance?
'use strict';
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {Permission,Place} = require('actions-on-google');
const app = dialogflow();
app.intent('Default Welcome Intent', conv => {
conv.close(`Welcome to my agent!`);
conv.ask('which type of ambulance would you like to book?');
});
app.intent('Default Fallback Intent', conv=> {
conv.close('sorry i did not understand');
});
app.intent('typeofambulance',conv => {
conv.ask('ac or non-ac?');
});
app.intent('ac', conv => {
conv.ask('do you want to book it from your current location?');
});
app.intent('location', (conv) => {
conv.data.requestedPermission = 'DEVICE_PRECISE_LOCATION';
return conv.ask(new Permission({
context: 'to locate you',
permissions: conv.data.requestedPermission,
}));
});
app.intent('receive', (conv, params, permissionGranted) => {
//conv.ask('rr');
if (permissionGranted) {
// conv.ask('entered');
const {
requestedPermission
} = conv.data;
const {
coordinates
} = conv.device.location;
conv.ask(`You are at latitude ${coordinates.latitude} and longitude
${coordinates.longitude}` );
conv.ask('destination please!');
} else {
return conv.close('Sorry, permission denied.');
}
});
app.intent('destination', conv => {
conv.ask(new Place({
prompt: 'Destination point?',
context: 'To find a place to pick you up',
}));
});
app.intent('actions.intent.PLACE', (conv, input, place, status) => {
if (place) {
conv.ask(` Ah, I see. You want to get dropped at
${place.formattedAddress}`);
const ll=place.formattedAddress;
}
else {
// Possibly do something with status
conv.ask(`Sorry, I couldn't find where you want to get picked up`);
}
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);