26 lines
655 B
Rust
26 lines
655 B
Rust
use std::str::FromStr;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
// #[wasm_bindgen]
|
|
// extern "C" {
|
|
// #[wasm_bindgen(js_namespace = console, js_name = log)]
|
|
// fn log_str(s: &str);
|
|
// }
|
|
|
|
#[wasm_bindgen]
|
|
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
|
|
xpin::Address::from_lat_lon(lat, lon)
|
|
.map(|a| a.to_string())
|
|
.map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn address_to_lat_lon(addr_str: &str) -> Result<Vec<f64>, String> {
|
|
xpin::Address::from_str(addr_str)
|
|
.as_ref()
|
|
.map_err(|e| e.to_string())
|
|
.map(xpin::Address::as_lat_lon)
|
|
.map(|(lat, lon)| vec![lat, lon])
|
|
}
|