pub fn __location__(
template: PageTemplate,
) -> Result<LocationData, LocationError>Expand description
Capture the user’s geographic location by opening the browser to a local consent page.
This is a blocking call. It:
- Binds a temporary HTTP server on a free
127.0.0.1port. - Opens
http://127.0.0.1:<port>/in the system’s default browser. - Waits for the browser to POST location data (or an error) back.
- Shuts the server down and returns the result.
Pass a PageTemplate to control what the user sees in the browser.
Use PageTemplate::default() for the built-in single-button consent page.
§Errors
| Variant | Cause |
|---|---|
LocationError::PermissionDenied | User denied the browser prompt. |
LocationError::PositionUnavailable | Device cannot determine position. |
LocationError::Timeout | No fix within the browser’s 30 s timeout. |
LocationError::ServerError | Failed to start the local HTTP server or runtime. |
§Example
use toolkit_zero::location::browser::{__location__, PageTemplate, LocationError};
// Default built-in page
match __location__(PageTemplate::default()) {
Ok(data) => println!("lat={:.6} lon={:.6} ±{:.0}m",
data.latitude, data.longitude, data.accuracy),
Err(LocationError::PermissionDenied) => eprintln!("access denied"),
Err(e) => eprintln!("error: {e}"),
}
// Tickbox page with custom consent label
let _ = __location__(PageTemplate::Tickbox {
title: None,
body_text: None,
consent_text: Some("I agree to share my location.".into()),
});§Note on async callers
If you are already inside a Tokio async context (e.g. inside
#[tokio::main]), use __location_async__ instead — it is the raw
async fn and avoids spawning an extra OS thread.