#geocoding #service #http-service #coordinates #nearest #find #suggest

geosuggest-core

按名称建议或根据坐标查找最近的市区

14 个不稳定版本 (3 个破坏性更新)

0.6.3 2024 年 6 月 15 日
0.6.2 2024 年 3 月 23 日
0.6.1 2024 年 2 月 19 日
0.6.0 2024 年 1 月 8 日
0.3.0 2023 年 8 月 18 日

#192 in HTTP 服务器

Download history 131/week @ 2024-04-27 139/week @ 2024-05-04 116/week @ 2024-05-11 153/week @ 2024-05-18 154/week @ 2024-05-25 167/week @ 2024-06-01 150/week @ 2024-06-08 350/week @ 2024-06-15 166/week @ 2024-06-22 137/week @ 2024-06-29 148/week @ 2024-07-06 162/week @ 2024-07-13 282/week @ 2024-07-20 306/week @ 2024-07-27 199/week @ 2024-08-03 166/week @ 2024-08-10

964 每月下载量
用于 2 crates

MIT 许可证

52KB
1K SLoC

geosuggest-core

用于建议和通过坐标查找最近城市市的库

实时演示源代码

HTTP 服务

示例

使用示例

use tokio;
use anyhow::Result;

use geosuggest_core::{Engine, storage::{self, IndexStorage}};
use geosuggest_utils::{IndexUpdater, IndexUpdaterSettings};

#[tokio::main]
async fn main() -> Result<()> {
    println!("Build index...");
    let engine = load_engine().await?;

    println!(
        "Suggest result: {:#?}",
        engine.suggest::<&str>("Beverley", 1, None, Some(&["us"]))
    );
    println!(
        "Reverse result: {:#?}",
        engine.reverse::<&str>((11.138298, 57.510973), 1, None, None)
    );

    Ok(())
}

async fn load_engine() -> Result<Engine> {
    let index_file = std::path::Path::new("/tmp/geosuggest-index.bincode");

    let updater = IndexUpdater::new(IndexUpdaterSettings {
        names: None, // no multilang support
        ..Default::default()
    })?;

    let storage = storage::bincode::Storage::new();

    Ok(if index_file.exists() {
        // load existed index
        let metadata = storage
            .read_metadata(index_file)
            .map_err(|e| anyhow::anyhow!("On load index metadata from {index_file:?}: {e}"))?;

        match metadata {
            Some(m) if updater.has_updates(&m).await? => {
                let engine = updater.build().await?;
                storage
                    .dump_to(index_file, &engine)
                    .map_err(|e| anyhow::anyhow!("Failed dump to {index_file:?}: {e}"))?;
                engine
            }
            _ => storage
                .load_from(index_file)
                .map_err(|e| anyhow::anyhow!("On load index from {index_file:?}: {e}"))?,
        }
    } else {
        // initial
        let engine = updater.build().await?;
        storage
            .dump_to(index_file, &engine)
            .map_err(|e| anyhow::anyhow!("Failed dump to {index_file:?}: {e}"))?;
        engine
    })

}

依赖项

~7–34MB
~480K SLoC