Get location from Alexa Skills Kit (ASK)

alexa skill geolocation
alexa developer console
alexa device address api
alexa skills developer
alexa skill get user id
alexa skill permissions
amazon alexa development kit
amazon echo development

I'm looking for a way to get the user's location, ideally longitude/latitude but address would work too, from the Alexa Skill Kit request to my custom skill. Also, I don't want to have to have the user link to an account on my app's side.

Is this possible? If so, how?


As per this thread on the Amazon Developer forums, there is not currently (as of May 2016) a way to get user location via the publicly available APIs. The only skills able to do so, such as Uber or Domino's, are utilizing APIs that are not available through the Alexa Skills Kit. However, there's hope that it may be added, as "Jamie@Amazon" left this reply in that discussion:

Hey there,

Thanks for posting.

This has now been added to the roadmap. Thanks for the feedback.

Jamie

However, at the time of writing, no further update has been provided regarding the implementation of such a feature.

Enhance Your Skill With Address Information, As per this thread on the Amazon Developer forums, there is not currently (as of May 2016) a way to get user location via the publicly available  Organizations and individuals can publish skills in the Alexa Skills Store to reach and delight customers on hundreds of millions of Alexa devices. The Alexa Skills Kit (ASK) provides self-service APIs and tools that you can use to build Alexa skills. You can also hire an agency with Alexa expertise to help your organization build a skill.


Amazon has now (2017-04-05) added this capability. See their blog post about their new Device Address API.

Using this new API you can get the address (either postal code or full address) of the device, as specified in the customer’s device settings.

From that you could use a geocoding API (such as is part of the Google Maps API) to translate the address into location coordinates.

Get location from Alexa Skills Kit (ASK), This is a sample skill written in JavaScript that demonstrates how to use device ID and AWS Lambda · Alexa Skills Kit (ASK); Device Address API When a user enables a skill with the Alexa app that wants to use location data, the user will  Typically you would test your skill in the Alexa Developer Portal, however, because the Alexa Simulator doesn't have a deviceId you will never be able to retrieve the location. If you have an Alexa device that is linked to the same email address as your Amazon Developer account you can test your skill on it.


As @Tom has pointed out, it is now possible to get the device address in your custom skill. If you are using Python to create your skill, it's pretty easy to implement the new API. I've written a detailed blog post about it here. It also describes how to get the corresponding coordinates for the retrieved address, so it might be useful for you. In short, here is a Python function to get you started. I use the very handy Flask-Ask library for my skill. Thus, it is easy to get the value of the deviceId and consentToken objects. These are included by Alexa in the JSON request sent to your skill. They are needed for constructing the request to the Amazon address API endpoint:

import requests
from flask_ask import Ask, context

def get_alexa_location():
    URL =  "https://api.amazonalexa.com/v1/devices/{}/settings" \
           "/address".format(context.System.device.deviceId)
    TOKEN =  context.System.user.permissions.consentToken
    HEADER = {'Accept': 'application/json',
             'Authorization': 'Bearer {}'.format(TOKEN)}
    r = requests.get(URL, headers=HEADER)
    if r.status_code == 200:
        return(r.json())

The function will return something like this on a successful call:

{u'city': u'Berlin', u'countryCode': u'DE',
u'addressLine1': u'42 Unter den Linden',
u'addressLine2': None, u'stateOrRegion': u'Berlin',
u'districtOrCounty': u'Berlin', u'postalCode': u'10117',
u'addressLine3': None}

You can use geopy to convert this address to coordinates.

Using the Alexa Skills Kit Device Address API to personalize Alexa , The Alexa Skills Kit SDK for Java helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate developer.amazon.com/ask​. Learn how Alexa skills work and how you can build one using the Alexa Skills Kit (ASK). Check out the different types of skills you can build, and explore the self-service APIs and tools that make it easy to get started. Get inspired by the delightful experiences others have built, then start bringing your own vision to life.


It is now possible to get the user's real-time geolocation (longitude/latitude) using the Alexa Location Services, which avoids having to integrate with a separate geocoding API as suggested by other answers. See the related blogpost for official information about this feature's release.

Provided that the device is compatible (context.System.device.supportedInterfaces.Geolocation exists), the location services are running and the alexa::devices:all:geolocation:read permission has been granted to your skill , you can retrieve a Geolocation object through the request's context, which will be equivalent to the following JSON payload:

"Geolocation":{ 
    "locationServices": { 
        "access": "ENABLED",
        "status": "RUNNING",   
    },
    "timestamp": "2018-03-25T00:00:00Z+00:00",
    "coordinate": {
        "latitudeInDegrees": 38.2,
        "longitudeInDegrees": 28.3,
        "accuracyInMeters": 12.1 
    },
    "altitude": {
        "altitudeInMeters": 120.1,
        "accuracyInMeters": 30.1
    },
    "heading": { 
        "directionInDegrees": 180.0,
        "accuracyInDegrees": 5.0  
    },
    "speed": { 
        "speedInMetersPerSecond": 10.0,
        "accuracyInMetresPerSecond": 1.1
    }       
}

alexa/skill-sample-node-device-address-api: This is a , The Alexa Skills Kit (ASK) is a collection of self-service APIs, tools, Find links to webinars and events nearby to come and learn from the experts. Conferences  The Alexa Skills Kit Command Line Interface (ask-cli) is used to create, manage, and deploy Alexa skills from the command line. Please see the full documentation from ASK CLI quick start guide . Note: To use ask-cli for Alexa-Hosted skill , please check our instructions for the usage.


Please follow the below URL to Get location from Alexa Skills Kit (ASK)

URL: https://api.eu.amazonalexa.com/v1/devices/{devicesId}/settings/address/countryAndPostalCode

Your Header would be something like below :

Host:api.eu.amazonalexa.com[keep your host you can get is from developer account during testing from json]
Accept:application/json
Authorization:Bearer [KEEP YOUR apiAccessToken here]

if request went success your will get response as below:

{
    "countryCode": "IN",
    "postalCode": "560102"
}

Make sure you have enabled permission in the Alexa app, and grants the permission of the respective skill please refer the bellow URL for more details of permission configuration

https://developer.amazon.com/blogs/alexa/post/0c975fc7-17dd-4f5c-8343-a37024b66c99/alexa-skill-recipe-using-the-device-address-api-to-request-information

alexa/alexa-skills-kit-sdk-for-java, Learn to build skills for Alexa using the Alexa Skills Kit and Amazon Web Services of Amazon Echo, the voice-enabled speaker from Amazon that allows you to get the word “Alexa”, followed by the request, like: _Alexa, ask History Buff w… Tens of thousands of developers have built skills using the Alexa Skills Kit (ASK), a collection of self-service APIs, tools, documentation, and code samples. With ASK, anyone can leverage Amazon’s knowledge in voice design to build quickly and easily.


Lektion "Discover the Alexa Skills Kit", The first dependency, ask-sdk is the Alexa Skills Kit SDK, and it will The last thing to do to get us started is to create a file that will hold all of  Quickly Build New Skills with the Alexa Skills Kit (ASK) Now you have the opportunity to easily extend your existing service or create something completely new. Without the need for customers to use their hands or eyes, they only have to “ask” and it’s at their command. Now is the time for you to get started. Get in Early.


Build Your First Alexa Skill (SDK v2), Alexa apps, called Alexa Skills, are what makes the digital assistant shine. like CNET News, you have to ask Alexa to enable the particular skill, Top 5: Ways Alexa can help you get work done (TechRepublic) use the Alexa Skills Kit to build Alexa Skills applicable to a particular Location Based Ads. New ASK SDK Support for Express.js and Jinja. All. Alexa Blog. Generally Available. 6/28/2019. Skills GameOn SDK. Easily integrate leaderboards into your game skills using the skills GameOn SDK (Beta) All. Alexa Blog. Beta. 4/18/2019. New SDK Features. ASK SDKs Are Now Easier to Use and Integrate. All. Documentation - Java Templates


Building an Alexa Skill with JavaScript and HERE Location Services , As per this thread on the Amazon Developer forums, there is not currently (as of May 2016) a way to get user location via the publicly available APIs. The only skills able to do so, such as Uber or Domino's, are utilizing APIs that are not available through the Alexa Skills Kit.