In an HTML page, include the SDK using a
In a web app, install the package from npm, then import the library:
The SDK is less than 20 KB minified.
To initialize the library, call:
publishableKey is a string containing your Radar publishable API key.
To identify the user when logged in, call:
userId is a stable unique ID for the user.
To set an optional dictionary of custom metadata for the user, call:
metadata is a JSON object with up to 16 keys and values of type string, boolean, or number.
Finally, to set an optional description for the user, displayed in the dashboard, call:
description is a string.
You only need to call these functions once, as these settings will be persisted across browser sessions in cookies.
Once you have initialized the SDK and the user has granted permissions, you can track the user's location.
The SDK uses the HTML5 geolocation API to determine the user's location.
To track the user's location, call:
If the request is unsuccessful,
err will be a string, one of:
ERROR_PUBLISHABLE_KEY: SDK not initialized
ERROR_PERMISSIONS: location permissions not granted
ERROR_LOCATION: location services error or timeout (10 seconds)
ERROR_NETWORK: network error or timeout (10 seconds)
ERROR_BAD_REQUEST: bad request (missing or invalid params)
ERROR_UNAUTHORIZED: unauthorized (invalid API key)
ERROR_PAYMENT_REQUIRED: payment required (organization disabled or usage exceeded)
ERROR_FORBIDDEN: forbidden (insufficient permissions or no beta access)
ERROR_NOT_FOUND: not found
ERROR_RATE_LIMIT: too many requests (rate limit exceeded)
ERROR_SERVER: internal server error
ERROR_UNKNOWN: unknown error
You can manually update the user's location by calling:
The web SDK also exposes APIs for anonymous context, geocoding, search, and distance.
Get a single location update without sending it to the server:
With the context API, get context for a location without sending device or user identifiers to the server:
With the forward geocoding API, geocode an address, converting address to coordinates:
With the reverse geocoding API, reverse geocode a location, converting coordinates to address:
With the IP geocoding API, geocode the device's current IP address, converting IP address to city, state, and country:
With the autocomplete API, autocomplete partial addresses and place names, sorted by relevance:
With the geofence search API, search for geofences near a location, sorted by distance:
With the places search API, search for places near a location, sorted by distance:
With the distance API, calculate the travel distance and duration between two locations:
Have questions? We're here to help! Email us at [email protected].