Stay organized with collections
Save and categorize content based on your preferences.
You can use the Google Mirror API to
observe the user's location in timeline items, request their
last known location directly, and subscribe
to periodic location updates. You can also deliver pre-rendered map images
in timeline cards by giving the Mirror API the coordinates to draw.
Retrieving the latest known location
To retrieve the latest known location for
the current user, send a GET request to the REST endpoint:
The Google Mirror API can render maps for you and overlay markers and lines to
signify important places and paths. Use the glass://map URI to request
a map. Here's an example:
h - The height in pixels of the returned map image
Only one of the items in the following list are additionally required,
but you can specify all of them:
center and zoom - The center (latitude,longitude) of the map to render
at and the zoom level. See Zoom Levels
for more information.
marker - Specify the pin markers to draw at the specified coordinates.
The marker parameter takes a marker type (0 indicates a pin
and 1, the current location), the latitude coordinate, and the
longitude coordinate.
The map automatically centers and zooms around the markers you create
if you don't explicitly specify center and zoom.
polyline - Specify the polyline coordinates to represent a path on the map.
Each polyline consists of a width and color followed by the
vertices in the polyline. For example: polyline=8,ffff0000;47.6,-122.34,47.62,-122.40
specifies an 8-pixel wide red line between (47.6,-122.34) and (47.62,-122.40).
The map is automatically centered and zoomed to fit the polyline if you don't
explicitly specify center and zoom.
The following example shows a best practice of how to display a map
image with some text and what it looks like:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe Google Mirror API allows you to observe user location, request their last known location, and subscribe to periodic location updates.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve the latest known user location by sending a GET request to the specified REST endpoint, requiring the \u003ccode\u003ehttps://www.googleapis.com/auth/glass.location\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eSubscribing to location updates is similar to subscribing to timeline updates, requiring a POST request to the subscriptions endpoint with specific parameters.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Mirror API can render pre-rendered map images within timeline cards using the \u003ccode\u003eglass://map\u003c/code\u003e URI, accepting parameters like width, height, markers, and polylines for customization.\u003c/p\u003e\n"]]],[],null,["# Location\n\nYou can use the Google Mirror API to\nobserve the user's location in timeline items, request their\n[last known location](/glass/v1/reference/locations/get) directly, and subscribe\nto periodic location updates. You can also deliver pre-rendered map images\nin timeline cards by giving the Mirror API the coordinates to draw.\n| **Note:** Retrieving users' location requires the additional `https://www.googleapis.com/auth/glass.location` scope.\n\nRetrieving the latest known location\n------------------------------------\n\nTo [retrieve](/glass/v1/reference/locations/get) the latest known location for\nthe current user, send a `GET` request to the REST endpoint: \n\n### Raw HTTP\n\n GET /mirror/v1/locations/ HTTP/1.1\n Authorization: Bearer {auth token}\n\nSubscribing to location updates\n-------------------------------\n\nSimilar to [subscribing to timeline updates](/glass/subscriptions),\nyou can subscribe to location updates by subscribing to the `locations`\ncollection. \n\n### Raw HTTP\n\n POST /mirror/v1/subscriptions HTTP/1.1\n Authorization: Bearer {auth token}\n Content-Type: application/json\n Content-Length: {length}\n\n {\n \"collection\": \"locations\",\n \"userToken\": \"harold_penguin\",\n \"verifyToken\": \"random_hash_to_verify_referer\",\n \"callbackUrl\": \"https://example.com/notify/callback\"\n }\n\n| **Note:** At this time, location notifications are sent every 10 minutes.\n\nRendering maps on timeline cards\n--------------------------------\n\nThe Google Mirror API can render maps for you and overlay markers and lines to\nsignify important places and paths. Use the `glass://map` URI to request\na map. Here's an example: \n\n \u003cimg src=\"glass://map?w=width&h=height&marker=0;latitude,longitude&marker=1;latitude,longitude&polyline=;latitude,longitude,latitude,longitude\"\n width=\"width\"\n height=\"height\"/\u003e\n\n| **Note:** Always specify the width and height of the image in the `\u003cimg\u003e` tag as well. This prevents reflows as the map image is being rendered.\n\nHere is a description of required parameters:\n\n- `w` - The width in pixels of the returned map image\n- `h` - The height in pixels of the returned map image\n\nOnly one of the items in the following list are additionally required,\nbut you can specify all of them:\n\n- `center` and `zoom` - The center (latitude,longitude) of the map to render at and the zoom level. See [Zoom Levels](/maps/documentation/staticmaps#Zoomlevels) for more information.\n- `marker` - Specify the pin markers to draw at the specified coordinates. The marker parameter takes a marker type (`0` indicates a `pin` and `1`, the current location), the latitude coordinate, and the longitude coordinate. The map automatically centers and zooms around the markers you create if you don't explicitly specify `center` and `zoom`.\n- `polyline` - Specify the polyline coordinates to represent a path on the map. Each polyline consists of a width and color followed by the vertices in the polyline. For example: `polyline=8,ffff0000;47.6,-122.34,47.62,-122.40` specifies an 8-pixel wide red line between (`47.6,-122.34`) and (`47.62,-122.40`). The map is automatically centered and zoomed to fit the polyline if you don't explicitly specify `center` and `zoom`.\n\nThe following example shows a best practice of how to display a map\nimage with some text and what it looks like: \n\n \u003carticle\u003e\n \u003cfigure\u003e\n \u003cimg src=\"glass://map?w=240&h=360&marker=0;42.369590,\n -71.107132&marker=1;42.36254,-71.08726&polyline=;42.36254,\n -71.08726,42.36297,-71.09364,42.36579,-71.09208,42.3697,\n -71.102,42.37105,-71.10104,42.37067,-71.1001,42.36561,\n -71.10406,42.36838,-71.10878,42.36968,-71.10703\"\n height=\"360\" width=\"240\"\u003e\n \u003c/figure\u003e\n \u003csection\u003e\n \u003cdiv class=\"text-auto-size\"\u003e\n \u003cp class=\"yellow\"\u003e12 minutes to home\u003c/p\u003e\u003cp\u003eMedium traffic on Broadway\u003c/p\u003e\n \u003c/div\u003e\n \u003c/section\u003e\n \u003c/article\u003e\n\n| **Note:** You can omit the color and width of the polyline like in this example. The map is rendered using the default color and width in this situation."]]