AWS

Developing Location-Aware Alexa Skills

By Michael Palermo | 31 May 2019

Every developer understands there are multiple interfaces for end-users to interact with technology – keyboard, mouse, touch-pad, touch-screen, pointing device, VR, AR, mixed reality, and voice. With the popularity of devices like Amazon Echo, voice-interactive experiences have enhanced how many engage technology within the home or office. In recent months, the Amazon Alexa team announced a new feature that provides access to the geolocation of participating Alexa-enabled devices. What does this mean? It provides an opportunity for end-users to interact with Alexa when away from home and allow custom experiences based on location.

From a developer's perspective, this could raise multiple questions:

  • What must be done to create a location-aware Alexa skill?
  • Which Alexa devices are supported, and can that be determined in code?
  • What about consumer privacy?
  • What location services are provided?

This post aims to answer all these questions.

How to Create a Location-Aware Skill

To enable location services, the developer needs to modify the permissions of the skill.  On the skill page in the developer console,  select Build > Permissions and enable the Location Services button.

alexa_location_permissions

In the screen capture above, the highlighted area needs toggled on. Also note near the top of the options that it is possible to request the address or general area of the device. This option is used for devices that are typically stationary, such as the Echo, Echo Dot, and Echo Show. 

Device Support

The current supported Amazon devices for location services include the Echo Auto and devices running the Alexa App. There is a way to determine in code if the device is even capable of supporting location services. When an end-user makes a request to an Alexa skill, the developer can check the context of the incoming request as follows:


var isGeolocationSupported = 
  context.System.device.supportedInterfaces.Geolocation;

If the code returns true, the device is capable of providing it's own geolocation.

Managing Permissions

If the device is capable, but the end=user has not granted permission, this should be handled in code.


var geo = context.Geolocation;
if (!geo || !geo.coordinate) {
  var permissions = context.System.user.permissions;
  var isGeoPermitted = 
    permissions.scopes['alexa::devices:all:geolocation:read']
    .status === "GRANTED";
    if ( !isGeoPermitted) {
    return responseBuilder
      .speak('YOUR SKILL NAME would like to use your location. ' +
      'To turn on location sharing, please go to your Alexa app, ' + 
      'and follow the instructions.')
      .withAskForPermissionsConsentCard(
        ['alexa::devices:all:geolocation:read']
      ).getResponse();
}

The above code checks first for the presence of the Geolocation object, and then for the sub=object of coordinate. If either are missing, the code prompts the user to grant permission to access location services.

 

Available Location Services

Once all checks have been cleared, the developer can access latitude and longitude.


var lat = geo.coordinate.latitudeInDegrees;
var lng = geo.coordinate.longitudeInDegrees;

With this geolocation data available, what now? What if the developer needs access to nearby places, weather, or a route to another location? This is possible by accessing our HERE APIs. Please explore the possibilities by viewing our available REST APIs!

If you'd like to learn more, watch the following webinar hosted by the Alexa team featuring yours truly.

AWS Alexa HERE Technologies webinar