use_geolocation
Reactive Geolocation API.
It allows the user to provide their location to web applications if they so desire. For privacy reasons, the user is asked for permission to report location information.
Demo
Usage
use leptos::prelude::*;
use leptos_use_geolocation::{use_geolocation, UseGeolocationReturn};
#[component]
fn Demo() -> impl IntoView {
let UseGeolocationReturn {
coords,
located_at,
error,
resume,
pause,
} = use_geolocation();
view! { }
}
SendWrapped Return
The returned closures pause and resume are sendwrapped functions. They can
only be called from the same thread that called use_geolocation.
Server-Side Rendering
Make sure you follow the instructions in Server-Side Rendering.
On the server all signals returns will always contain None and the functions do nothing.
Installation
cargo add leptos-use-geolocation
Options
UseGeolocationOptions
Options for use_geolocation_with_options.
Every option is set with a builder method of the same name, e.g. UseGeolocationOptions::default().immediate(...). See also the API docs.
immediate
Type: bool
If true the geolocation watch is started when this function is called.
If false you have to call resume manually to start it. Defaults to true.
enable_high_accuracy
Type: bool
A boolean value that indicates the application would like to receive the best
possible results. If true and if the device is able to provide a more accurate
position, it will do so. Note that this can result in slower response times or
increased power consumption (with a GPS chip on a mobile device for example).
On the other hand, if false, the device can take the liberty to save
resources by responding more quickly and/or using less power. Default: false.
maximum_age
Type: u32
A positive value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return.
If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position.
Default: 30000.
timeout
Type: u32
A positive value representing the maximum length of time (in milliseconds) the device is allowed to take in order to return a position. The default value is 27000.