in dialogflow-prebuilt-agents/client_side_messenger/airline_support/airline_support.js [340:369]
async function getGeolocation() {
dfMessenger.renderCustomText(
'We\'re working on finding your location. This might take a moment.',
true);
const getPositionPromise = (options) => new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
const currentDate = new Date().toLocaleDateString();
try {
const position = await getPositionPromise();
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const result =
await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${
latitude}&lon=${longitude}&format=json`);
const resultJson = await result.json();
const geolocationOutput = {
address: resultJson.address,
currentDate: currentDate
};
// Return the combined geolocation info and current date
return geolocationOutput;
} catch (error) {
// Handle errors (permission denied, etc.)
console.error('Error getting geolocation:', error);
return {currentDate: currentDate};
}
}