An API client for Komoot's Photon API written in and for Rust.
It supports forward and reverse geocoding as well as search-as-you-type.
The main repository is hosted on codeberg.org. Issues and Pull Requests are preferred there, but you can still open one on GitHub.
Photon is a free and open-source API hosted by Komoot and powered by ElasticSearch. It returns data from the OpenStreetMap project, which is licensed under the ODbL License.
The API is available at photon.komoot.io and licensed under the Apache 2.0 License.
Important: Please be aware of the Terms and Use of Photon! It is free to use, so please be fair and avoid excessive requests!
In your cargo.toml
, include this:
toml
[dependencies]
photon-geocoding = { version = "1.0" }
Forward geocoding: ```rust use photon_geocoding::{PhotonApiClient, PhotonFeature};
let api: PhotonApiClient = PhotonApiClient::default();
let result: Vec
Reverse geocoding: ```rust use photon_geocoding::{PhotonApiClient, PhotonFeature};
let api: PhotonApiClient = PhotonApiClient::default();
let result: Vec
Self-hosted instances (custom URL): ```rust use photon_geocoding::PhotonApiClient;
let api: PhotonApiClient = PhotonApiClient::new("https://example.com"); // requests will now go to https://example.com/api and https://example.com/reverse ```
Filters: ```rust use photongeocoding::filter::{ForwardFilter, PhotonLayer}; use photongeocoding::{BoundingBox, LatLon, PhotonApiClient};
let api: PhotonApiClient = PhotonApiClient::default(); let filter = ForwardFilter::new() .language("FR") .boundingbox(BoundingBox { southwest: LatLon::new(40.0, 10.0), northeast: LatLon::new(50.0, 15.0), }) .layer(vec![PhotonLayer::City, PhotonLayer::State]) .additionalquery(vec![("osm_tag", "!key:value")]);
let results = api.forward_search("munich", Some(filter)).unwrap();
// resulting query string: "q=munich&bbox=10%2C40%2C15%2C50&lang=fr&layer=city&layer=state&osm_tag=%21key%3Avalue" ```
Feel free to open a new issue! I am always happy to improve this package.
As I am fairly new to Rust, please also don't hesitate to suggest improvements on code style and/or usability (especially regarding ownership, borrowing etc.)!
Feel free to open pull requests and help to improve this package!