# latlng
Rust SDK for [latlng.work](https://latlng.work), a geocoding and places API
powered by OpenStreetMap data.
## Install
```toml
[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:
```toml
[dependencies]
latlng = { version = "0.1", default-features = false, features = ["native-tls"] }
```
## Quick start
```rust,no_run
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:
```rust,no_run
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`:
```toml
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
```