use toolkit_zero::location::browser::{
PageTemplate, LocationData, LocationError,
__location__, __location_async__,
browser,
};
#[allow(dead_code)]
fn template_examples() {
let _default = PageTemplate::default();
let _custom_title = PageTemplate::Default {
title: Some("My App — Share Location".into()),
body_text: Some("This app needs your location to show nearby results.".into()),
};
let _tickbox = PageTemplate::Tickbox {
title: Some("Location Consent".into()),
body_text: None,
consent_text: Some("I agree to share my location with this application.".into()),
};
let _custom_html = PageTemplate::Custom(
r#"<!DOCTYPE html>
<html>
<head><title>Where are you?</title></head>
<body>
<h1>Share your location</h1>
{}
<p id="status"></p>
</body>
</html>"#
.into(),
);
}
#[allow(dead_code)]
async fn browser_macro_forms() -> Result<LocationData, LocationError> {
#[browser]
fn loc() {}
Ok(loc)
}
#[allow(dead_code)]
async fn browser_macro_tickbox() -> Result<LocationData, LocationError> {
#[browser(tickbox, title = "Verify Location", consent = "I agree")]
fn loc() {}
Ok(loc)
}
#[allow(dead_code)]
fn browser_macro_sync() -> Result<LocationData, LocationError> {
#[browser(sync, title = "My App")]
fn loc() {}
Ok(loc)
}
fn print_location(label: &str, data: &LocationData) {
println!("{label}");
println!(" latitude : {:.6}°", data.latitude);
println!(" longitude : {:.6}°", data.longitude);
println!(" accuracy : {:.1} m (95% confidence radius)", data.accuracy);
if let Some(alt) = data.altitude {
println!(" altitude : {alt:.1} m");
}
if let Some(spd) = data.speed {
println!(" speed : {spd:.1} m/s");
}
}
#[tokio::main]
async fn main() {
println!("=== location_browser example ===\n");
println!("Opening browser to acquire location (async)…");
match __location_async__(PageTemplate::default()).await {
Ok(data) => print_location("Async result:", &data),
Err(LocationError::PermissionDenied) => {
eprintln!("Location permission denied — skipping async call.");
}
Err(e) => eprintln!("Async location error: {e}"),
}
println!();
println!("Opening browser to acquire location (blocking)…");
let template = PageTemplate::Tickbox {
title: Some("Confirm Location".into()),
body_text: None,
consent_text: Some("I allow this example to read my location.".into()),
};
match __location__(template) {
Ok(data) => print_location("Blocking result:", &data),
Err(LocationError::PermissionDenied) => {
eprintln!("Location permission denied — skipping blocking call.");
}
Err(e) => eprintln!("Blocking location error: {e}"),
}
}