radar-sdk-js package on npm here.
Install
In an HTML page, add the SDK script:Setup
Initialize
Initialize the library with your publishable API key, found on the Settings page:You must initialize the library before calling any other functions.
Geofencing
Identify user
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.
Learn more about when Radar creates new user records here.
Foreground tracking
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:err will be one of:
RadarPublishableKeyError: SDK not initializedRadarLocationPermissionsError: location permissions not grantedRadarLocationError: location services error or timeout (10 seconds)RadarTimeoutError: network timeout (10 seconds)RadarBadRequestError: bad request (missing or invalid params)RadarUnknownError: unauthorized (invalid API key)RadarPaymentRequiredError: payment required (organization disabled or usage exceeded)RadarForbiddenError: forbidden (insufficient permissions or no beta access)RadarNotFoundError: not foundRadarRateLimitError: too many requests (rate limit exceeded)RadarServerError: internal server errorRadarUnknownError: unknown error
err will include an HTTP response code and the API response body:
Manual tracking
Alternatively, you can manually update the user’s location with any location by calling:Maps
Geocoding
With the forward geocoding API, geocode an address, converting address to coordinates:Search
With the autocomplete API, autocomplete partial addresses and place names, sorted by relevance:Distance
With the distance API, calculate the travel distance and duration between two locations:Matrix
With the matrix API, calculate the travel distances and durations between multiple origins and destinations for up to 25 routes:Maps and UI kits
The React Native SDK also has UI components for maps and address autocomplete. Learn more in the Maps Platform documentation.Request IDs
Every API response includes anX-Radar-Request-ID header with a unique identifier for the request. The Web SDK surfaces this identifier as meta.requestId on the API response body.
If a request fails, get the request ID from the API response body on the error:
debug option enabled, the API response body is also included on successful results, as response: