latlng 0.1.0

Rust SDK for the latlng.work geocoding and places API
Documentation

latlng

Rust SDK for latlng.work, a geocoding and places API powered by OpenStreetMap data.

Install

[dependencies]
latlng = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

By default, the crate uses rustls for TLS. To use native TLS instead:

[dependencies]
latlng = { version = "0.1", default-features = false, features = ["native-tls"] }

Quick start

use latlng::LatlngClient;

#[tokio::main]
async fn main() -> latlng::Result<()> {
    let client = LatlngClient::with_api_key("latlng_xxxxx")?;

    let result = client.geocode("Eiffel Tower, Paris").await?;
    if let Some(place) = result.first() {
        println!("{}, {}", place.lat, place.lon);
    }

    let nearby = client
        .places()
        .nearby(48.8584, 2.2945)
        .radius(500)
        .limit(10)
        .send()
        .await?;

    for place in nearby.places {
        println!("{} {:?}", place.name, place.category);
    }

    Ok(())
}

Anonymous requests are supported, but have lower rate limits:

use latlng::LatlngClient;

#[tokio::main]
async fn main() -> latlng::Result<()> {
    let client = LatlngClient::anonymous()?;
    let berlin = client.geocode("Berlin").await?;
    println!("{:?}", berlin.first());
    Ok(())
}

API surface

  • LatlngClient::geocode for forward geocoding.
  • LatlngClient::reverse for reverse geocoding.
  • LatlngClient::places().nearby for points of interest near a coordinate.
  • LatlngClient::places().search for full-text place search.
  • LatlngClient::places().autosuggest for typeahead suggestions via https://suggest.latlng.work/autosuggest.
  • LatlngClient::places().categories for available place categories.

All methods are async and return latlng::Result<T>.

docs.rs

This crate is configured for docs.rs in Cargo.toml:

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]