Location
Detecting location changes
SDK hook: useGeolocation
useGeolocationA hook that returns the device's location information. When the location changes, the value changes too. It detects the current location using GPS information and automatically updates as the user moves. For example, it can be used to display the user's current location in a map-based service or to track real-time routes in a delivery app. You can adjust the accuracy and update frequency of location information, allowing you to maintain the required level of accuracy while minimizing battery consumption.
Signature
function useGeolocation({ accuracy, distanceInterval, timeInterval }: UseGeolocationOptions): Location | null;Parameters
options · Required ·
UseGeolocationOptionsConfiguration object needed for location detection.
options.accuracy ·
AccuracySets the location accuracy.
Accuracy.Lowest: within 3 km margin of error,Accuracy.Low: within 1 km margin of error,Accuracy.Balanced: within a few hundred meters margin of error,Accuracy.High: within 10 m margin of error,Accuracy.Highest: highest accuracy,Accuracy.BestForNavigation: best accuracy for navigationoptions.timeInterval ·
numberThe minimum interval for updating location information, in milliseconds (ms). This value sets the shortest interval at which location updates occur, but due to system or environmental factors, updates may happen at a longer interval than specified.
options.distanceInterval ·
numberSets the location change distance in meters (m).
Return value
Location | null
Returns an object containing the device's location information. For details, Locationplease refer to.
Example
Displaying location information on screen
Try the sample app
apps-in-toss-examples from the repository with-location-tracking Download the code, or scan the QR code below to try it yourself.
QR code link: intoss://with-location-tracking
Last updated
Was this helpful?