With Actions on Google, what is the recommended way to get the user's country with coarse location information?


Question: 

The getDeviceLocation() call may return either lat/lon coordinates if the surface provides precise location information or a ZIP code and a city for coarse location information.

With the former one can use the Google Maps API to reverse-geocode the coordinates, the latter, however, can be ambiguous as there is no country information provided. Is there a recommended way to disambiguate the device location if only coarse permissions are provided?

For a more concrete example:

const requestedPermission = app.data.requestedPermission;
const permissions = app.SupportedPermissions;
if (requestedPermission === permissions.DEVICE_COARSE_LOCATION) {
  // Not available! We've only got .zipCode and .city.
  const countryCode = app.getDeviceLocation().countryCode;
  doSomethingBasedOnCountry(countryCode);
}
if (requestedPermission === permissions.DEVICE_PRECISE_LOCATION) {
  const { coordinates } = app.getDeviceLocation();
  return coordinatesToCountryCode(mapsClient, coordinates.latitude, coordinates.longitude)
    .then(doSomethingBasedOnCountry);
}



1 Answer: 

 

More Articles


actions on google - Implementing Conversation Webhook as Azure Function App

I have an azure function app that I am using as a webhook for my google assistant action. I've tried to follow the documentation for the proper response but I continually get the following error in the simulator when testing my webhook. Is there anything in my response message that looks wrong?Fai

node.js - Correct way to send response when using Actions-on-google with koa.js

I'm trying to use actions-on-google with koa framework. I can't understand which request and response to use with AoG constructor in koa middleware. This is my code:const Koa = require( 'koa' )const koaBody = require('koa-body')const { DialogflowApp } = require('actions-on-google')const koaApp = new

Logs showing WARNING when trying to credit bank accounts with Balanced Payments

Been seeing this in my logs today. ############################################################# # WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! # ############################################################# Using positional arguments is **DEPRECATED**. Please use the keyword optio


node.js - BotBuilder TypeError: builder.ConsoleConnector is not a constructor

I'm following the official quick start of Microsoft Bot Builder(SDK v3) for NodeJs: Create a bot with the Bot Builder SDK for Node.js 1- I made a new project with npm init2- then npm install --save botbuilder3- then I created a new file "app.js"var builder = require('botbuilder');var connector =

I came across the new Stack Overflow Bot by Microsoft on the Stack Overflow blog and decided to give it a try.After installing Node V8.1.4 for macOS, I installed the bot by running npm install in the StackBot directory. There weren't many issues, except for a warning returned.MacBook-Air:StackBot US

actions on google - Request Sync always returns 404 : "Error: Requested entity was not found."

I'm having a hard time implementing requestSync. It always returns "error": { "code": 404, "message": "Requested entity was not found.", "status": "NOT_FOUND" }I use Node.js/Express for the backend. The linking/unlinking with the Google Home app work and my actions work as well. It's rea


java - How can I use the response from a JOptionPane?

This is the first time I have used a confirm box and I'd like some advice on how to use it please, I want to use the users input of "Yes or No" but not sure how to do it? If I wanted to reference the input from the JOptionPane in an if statement how would go about it?JOptionPane.showConfirmDialog(nu

dialogflow - how to define 'App' statement in firestore database?

I have to define 'app' inorder to store user details from dialogflow to firestore databaseconst app = new App({request:request, response:response});inorder to use this line of code i need 'App' to be defined in firestore code,for which i have used this line,const App = require('firebase-functions')

Magento: Where does Magento 1.8 store payment method options in the database?

Where does Magento store payment method options in the database?I looked around and did not find it.

java - JFrame as a dialog

I want to customize the jframe and that frame should work like a joptionpane. which is relative with parent. can i do like this. if it is possible please any one help me.