Location Services Configuration

Hello all, I am currently trying to use documentation from Amazon Alexa website on location services to get GPS coordinates from a users phone to give them weather info based on longitude and latitude.

I have used the custom code in the Alexa documentation ( https://developer.amazon.com/en-US/docs/alexa/custom-skills/location-services-for-alexa-skills.html ) to hopefully get GPS coordinates and to check freshness of data and get longitude and latitude values.

However, I am not sure if I am storing the returned data correctly since I can’t test the custom code. Should there be a better way to store variables from custom code or do you just configure it and hope that it returns the response data you are looking for?

I will attach images to better show you as I am improving my technical communication skills.

As you can see, I am trying to store longitude and latitude from the custom code, but I have no idea if I even wrote the response names correctly to be stored. I will test out on my end, but I wanted to put this here in case anyone else has gotten location services for user phone to work.

The first custom code block is to get data and the second one is to check the freshness of the data

you seem to try to access “context” object which is included in Alexa’s response, but you cannot get Alexa’s raw and whole response directly in Voiceflow.

Instead ot that, if users grant permissions to access location data, user info block returns location data like this. In this example, I put its response into a variable “location”.

{
    "location":{
        "locationServices":{
            "status":"RUNNING",
            "access":"ENABLED"
        },
        "timestamp":"2019-11-29T12:29:42Z",
        "coordinate":{
            "latitudeInDegrees":34.6826XXXXXXXXXX,
            "longitudeInDegrees":135.1867XXXXXXXXX,
            "accuracyInMeters":10
        },
        "altitude":{
            "altitudeInMeters":8.5653XXXXXXXXXXX,
            "accuracyInMeters":10
        },
        "speed":{
            "speedInMetersPerSecond":1
        }
    }
}

now you can get location data via location.coordinate.latitudeInDegrees and location.coordinate.longtitudeInDegrees.

Also, if you wanna check users’ devices support geolocation, you can do like this via code block.

if (voiceflow.capabilities && ('Geolocation' in voiceflow.capabilities)) {
  hasGeolocation = 1;
} else {
  hasGeolocation = 0;
}
1 Like

Thank you so much for this, this was exactly what I needed. Do I create a variable to store ( response.altitude) or is it already a variable.

I’m guessing I can just use location.coordinate.latitudeInDegrees and location.coordinate.longtitudeInDegrees to put the attributes into the API

So I just call the variable like {location}.coordinate.latitudeInDegrees or do I just write it out in custom code like location.coordinate.latitudeInDegrees

I’m trying to see how I can put it into a variable.

I’m going to try and use set blocks to set variables called longitude and latitude to be equal to a users lon and lat values from the user info block

Should this work, just set the longitude and latitude to the variable names I used (I used user_location as the variable name) instead of just location and did .coordinate.LongitudeInDegrees

Hello,
Is there somewhere a complete example, step by step to use location service with Alexa ?
Every search I make bring me back to this topic, so i’m lost.
thank’s by advance for your help

there’s a demo for location service in the market place. might be a litttle old, but you should check.

Hello kun432, thank you very much. I will check right know and Voiceflow Community Marketplace - Airtable is added to my favorites ^^