pub fn use_geolocation<'hook>() -> impl 'hook + Hook<Output = UseGeolocationState>Expand description
A sensor hook that tracks user’s geographic location.
§Example
use yew_hooks::prelude::*;
#[function_component(UseGeolocation)]
fn geolocation() -> Html {
let state = use_geolocation();
html! {
<>
<b>{ " loading: " }</b>
{ state.loading }
<b>{ " latitude: " }</b>
{ state.latitude }
<b>{ " longitude: " }</b>
{ state.longitude }
<b>{ " altitude: " }</b>
{ state.altitude.unwrap_or_default() }
<b>{ " altitude_accuracy: " }</b>
{ state.altitude_accuracy.unwrap_or_default() }
<b>{ " heading: " }</b>
{ state.heading.unwrap_or_default() }
<b>{ " speed: " }</b>
{ state.speed.unwrap_or_default() }
<b>{ " timestamp: " }</b>
{ state.timestamp }
</>
}
}§Note
When used in function components and hooks, this hook is equivalent to:
/// A sensor hook that tracks user's geographic location.
///
/// # Example
///
/// ```rust
/// # use yew::prelude::*;
/// #
/// use yew_hooks::prelude::*;
///
/// #[function_component(UseGeolocation)]
/// fn geolocation() -> Html {
/// let state = use_geolocation();
///
/// html! {
/// <>
/// <b>{ " loading: " }</b>
/// { state.loading }
/// <b>{ " latitude: " }</b>
/// { state.latitude }
/// <b>{ " longitude: " }</b>
/// { state.longitude }
/// <b>{ " altitude: " }</b>
/// { state.altitude.unwrap_or_default() }
/// <b>{ " altitude_accuracy: " }</b>
/// { state.altitude_accuracy.unwrap_or_default() }
/// <b>{ " heading: " }</b>
/// { state.heading.unwrap_or_default() }
/// <b>{ " speed: " }</b>
/// { state.speed.unwrap_or_default() }
/// <b>{ " timestamp: " }</b>
/// { state.timestamp }
/// </>
/// }
/// }
/// ```
pub fn use_geolocation() -> UseGeolocationState {
/* implementation omitted */
}