Skip to Content
ProvidersLocation Provider

Maps UI SDK - Location Provider

A context provider for managing location data and formatting across your application.

API reference

LocationProvider

The main provider component that wraps your application to provide location functionality.

OptionDescriptionDefault
childrenType: ReactNode (required)The child components that will have access to the location context.
coordinatesType: Coordinates | null (optional)Current coordinates value. Can be used as an initial value or as a controlled value; pass null to clear.
formatterType: CoordinatesFormatter (optional)Custom formatter function for coordinates.
onChangeType: (coordinates: Coordinates | null) => void (optional)Called whenever coordinates change, including when they are cleared (null).

useLocationContext

A custom hook to access the location context within child components.

Returns an object with the following properties:

NameTypeDescription
coordinatesCoordinates | nullThe current coordinates, or null when unset.
formattedCoordinatesFormattedCoordinates | nullStructured formatted coordinates, or null if there are no coordinates or no formatter.
coordinatesStringstring | nullThe coordinates as a formatted string, or null when unset.
setCoordinates(newCoordinates: Coordinates | null) => voidUpdates the coordinates; pass null to clear the current selection.

Types

Coordinates

The structure of the coordinates object.

interface Coordinates { lat: number; lon: number; }

FormattedCoordinates

The structure of the formatted coordinates object.

interface FormattedCoordinates { lat: string | number; lon: string | number; }

CoordinatesFormatter

The type for the custom formatter function.

type CoordinatesFormatter = (coordinates: Coordinates) => FormattedCoordinates;
© 2026 Xweather (opens in a new tab)Terms of Service (opens in a new tab)Privacy Policy (opens in a new tab)