Use session.location to get the user’s GPS coordinates. You can read the cached position, subscribe to continuous updates, or request a fresh location fix.

Read Cached Location

The LocationManager caches the latest known position. Read it anytime:
const lat = session.location.lat;
const lng = session.location.lng;

if (lat !== null && lng !== null) {
  session.display.showTextWall(`${lat.toFixed(4)}, ${lng.toFixed(4)}`);
}
Available cached properties:
PropertyTypeDescription
session.location.latnumber | nullLatitude (null if no location received yet)
session.location.lngnumber | nullLongitude (null if no location received yet)
session.location.accuracynumber | nullAccuracy in meters
session.location.timestampnumber | nullUnix timestamp (ms) of the last update

Subscribe to Updates

Get continuous location updates as the user moves:
const cleanup = session.location.onUpdate((data) => {
  session.display.showTextWall(`Location: ${data.lat}, ${data.lng}`);
});

// Stop receiving updates
cleanup();

Request a Fresh Location

Request a one-shot location poll. The result arrives via your onUpdate listener:
// Set up listener first
session.location.onUpdate((data) => {
  session.display.showTextWall(`Fresh: ${data.lat}, ${data.lng}`);
});

// Then request a fresh fix
session.location.requestUpdate("high");
The accuracy parameter is optional (defaults to "standard").

Common Patterns

Show location on session start

app.onSession((session) => {
  // Subscribe to updates
  session.location.onUpdate((data) => {
    session.display.showTextWall(`${data.lat.toFixed(4)}, ${data.lng.toFixed(4)}`);
  });

  // Request a fresh location
  session.location.requestUpdate("high");
});

Stop location updates

Stop all location tracking and clean up resources:
session.location.stop();
This unsubscribes all onUpdate listeners and stops GPS polling. You can call onUpdate() again later to resume.

Location-aware content

session.location.onUpdate(async (data) => {
  const nearby = await fetchNearbyPlaces(data.lat, data.lng);
  session.display.showReferenceCard("Nearby", nearby.map(p => p.name).join("\n"));
});

Timezone from coordinates

import tzlookup from "tz-lookup";

session.location.onUpdate((data) => {
  const timezone = tzlookup(data.lat, data.lng);
  session.logger.info(`User timezone: ${timezone}`);
});

Permissions

Your app needs the location permission to access GPS data. Add it in the Developer Console when creating or editing your app. Without location permission, session.location.hasPermission returns false, cached values stay null, and onUpdate receives no events.

Migrating from v2

// v2
session.location.getLatestLocation({ accuracy: "high" });
session.location.subscribeToStream({ accuracy: "standard" }, (data) => { ... });
session.events.onLocationUpdate((data) => { ... });

// v3
session.location.lat;                          // cached latitude
session.location.lng;                          // cached longitude
session.location.onUpdate((data) => { ... });  // subscribe to updates (returns cleanup function)
session.location.requestUpdate("high");        // request a fresh fix
getLatestLocation is available via the v2 compat shim during v3.0. The native v3 pattern is to read the cached lat/lng properties or use requestUpdate() + onUpdate(). See the Migration Guide for the full list of changes.