This is the documentation for the Radar Web SDK.
The source can be found on GitHub here. Or, see the radar-sdk-js package on npm here.
Install
In an HTML page, add the SDK script and stylesheet:
In a web app, install the package from npm:
The SDK has a dependency on maplibre-gl.
Then, import the library and stylesheet:
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.
Optionally, you can specify configuration options:
The initialize call takes an optional second argument that is an object with additional configuration options.
Available options include:
Geofencing
Identify user
To identify the user when logged in, call:
where userId is a stable unique ID for the user.
To set an optional dictionary of custom metadata for the user, call:
where 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:
where 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:
If the request fails, err will be one of:
RadarPublishableKeyError: SDK not initialized
RadarLocationPermissionsError: location permissions not granted
RadarLocationError: 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 found
RadarRateLimitError: too many requests (rate limit exceeded)
RadarServerError: internal server error
RadarUnknownError: unknown error
If the error is the result of a failed API call, 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:
Get location
You can also get a single location update without sending it to the server:
Context
With the context API, get context for a location without sending device or user identifiers to the server:
Maps
Geocoding
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:
Search
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 address validation API, validate a structured address in the US or Canada:
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.
Support
Have questions? We’re here to help! Contact us at radar.com/support.