Using the Navigate action in a menu item in Python for Glass Mirror API

 

Recently I was working on a simple Google Glass application using the Mirror API and wanted to add a menu item with the action value of Navigate. What Navigate does is provide navigation directions to a predefined or programmatically generated location. My problem was is that it was not clear from the menuItems reference guide who to build out the location object. For Glass you need to first create a location JSON object that looks like this:

 

{
  “kind”:
“mirror#location”,
  “id”:
string,
  “timestamp”:
datetime,
  “latitude”:
double,
  “longitude”:
double,
  “accuracy”:
double,
  “displayName”:
string,
  “address”:
string
}

 

This needs to be embedded in your mail JSON object. For example in my application I have a python variable were I build the JSON that needs to be passed to the Mirror API that looks like:

 

body = {

‘notification’: {‘level’: ‘DEFAULT’},

‘location’: { ‘kind’: ‘mirror#location’, ‘id’: ‘home’, ‘latitude’: 38.935963, ‘longitude’: -77.159423, ‘displayName’: ‘Home’},

‘title’: ‘hello world’,

‘html’: template.render(),

‘text’: ‘Hello?’,

‘speakableText’: ‘Hello World’,

‘menuItems’: [

{‘action’: ‘READ_ALOUD’},

{‘action’: ‘TOGGLE_PINNED’},

{‘action’: ‘REPLY’},

{‘action’: ‘PLAY_VIDEO’, ‘payload’ : ‘http://localhost:8080/static/videos/clipcanvas_14348_H264_640x360.mp4’},

{‘action’: ‘OPEN_URI’, ‘payload’ : ‘http://www.google.com’},

{‘action’: ‘SHARE’},

{‘action’: ‘VOICE_CALL’},

{‘action’: ‘NAVIGATE’},

{‘action’: ‘DELETE’}

]

}

 

self.mirror_service.timeline().insert(body=body).execute()

self.response.out.write(template.render(template_values))

 

This will then build a timeline item with a menu option of navigate that will start at your current location and let you navigate to Seven Locks Park or whatever location you put in the lat and long fields.

Advertisements

About ordo tacitus

ordo tacitus
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s