26 lines
655 B
Rust
Raw Normal View History

2023-02-25 14:49:09 -05:00
use std::str::FromStr;
2023-02-25 11:14:25 -05:00
use wasm_bindgen::prelude::*;
2023-02-28 09:20:06 -05:00
// #[wasm_bindgen]
// extern "C" {
// #[wasm_bindgen(js_namespace = console, js_name = log)]
// fn log_str(s: &str);
// }
2023-02-25 11:14:25 -05:00
#[wasm_bindgen]
2023-02-25 14:49:09 -05:00
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
2023-03-02 18:55:40 -05:00
xpin::Address::from_lat_lon(lat, lon)
2023-02-25 14:12:18 -05:00
.map(|a| a.to_string())
.map_err(|e| e.to_string())
2023-02-25 11:14:25 -05:00
}
2023-02-25 14:12:18 -05:00
2023-02-25 14:49:09 -05:00
#[wasm_bindgen]
pub fn address_to_lat_lon(addr_str: &str) -> Result<Vec<f64>, String> {
2023-03-02 18:55:40 -05:00
xpin::Address::from_str(addr_str)
2023-02-25 14:49:09 -05:00
.as_ref()
.map_err(|e| e.to_string())
2023-03-02 18:55:40 -05:00
.map(xpin::Address::as_lat_lon)
2023-02-25 14:49:09 -05:00
.map(|(lat, lon)| vec![lat, lon])
}