Geolocation Widget
General purpose widget for turning postal codes into latitude and longitude.
Example
window.dtn.geolocation.createGeolocationWidget({
});
Types
Coordinates
type Coordinates = {
latitude: number; longitude: number;
}
The Coordinates type describes a point on Earth with a latitude and longitude.
PostalCode
type PostalCode = { postalCode: string };
The PostalCode type describes a North American postal code.
Configuration
apiKey
apiKey: string;
The widget access api key associated with your DTN account.
container
container: HTMLElement | string;
The container to mount the widget on. This can be a reference to an HTML element, or a valid selector string. If a string is encountered, document.querySelector will be used to search document for the container.
defaultLocation
defaultLocation?: PostalCode | unknown;
Use the optional `defaultLocation` option to provide an initial query. This will result in the `onLocationChange` callback firing without any end-user interaction.
Methods
query
query: (
query: PostalCode | unknown
) => void;
Programmatically set and query the geolocation widget. This is the equivalent of calling `setQuery` and then submitting the query.
setQuery
setQuery: (
query: PostalCode | unknown
) => void;
Set the query shown in the input field. This is essentially pre-populating the input without actually running the query.
Callbacks
onLocationChange
onLocationChange: (location?: Coordinates) => void;
This callback will be called whenever a geolocation query is submitted. If the query returns no results, this callback will be called with no arguments.