pub struct Opencage<'a> {
pub parameters: Parameters<'a>,
/* private fields */
}
Expand description
An instance of the Opencage Geocoding service
Fields§
§parameters: Parameters<'a>
Implementations§
Source§impl<'a> Opencage<'a>
impl<'a> Opencage<'a>
Sourcepub fn remaining_calls(&self) -> Option<i32>
pub fn remaining_calls(&self) -> Option<i32>
Retrieve the remaining API calls in your daily quota
Initially, this value is None
. Any OpenCage API call using a “Free Tier” key
will update this value to reflect the remaining quota for the API key.
See the API docs for details.
Sourcepub async fn reverse_full<T>(
&self,
point: &Point<T>,
) -> Result<OpencageResponse<T>, GeocodingError>
pub async fn reverse_full<T>( &self, point: &Point<T>, ) -> Result<OpencageResponse<T>, GeocodingError>
A reverse lookup of a point, returning an annotated response.
This method passes the no_record
parameter to the API.
§Examples
use geocoding_async::{Opencage, Point};
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let p = Point::new(2.12870, 41.40139);
// a full `OpencageResponse` struct
let res = oc.reverse_full(&p).await.unwrap();
// responses may include multiple results
let first_result = &res.results[0];
assert_eq!(
first_result.components["road"],
"Carrer de Calatrava"
);
Sourcepub async fn forward_full<T, U>(
&self,
place: &str,
bounds: U,
) -> Result<OpencageResponse<T>, GeocodingError>
pub async fn forward_full<T, U>( &self, place: &str, bounds: U, ) -> Result<OpencageResponse<T>, GeocodingError>
A forward-geocoding lookup of an address, returning an annotated response.
it is recommended that you restrict the search space by passing a
bounding box to search within.
If you don’t need or want to restrict the search using a bounding box (usually not recommended), you
may pass the NOBOX
static value instead.
Please see the documentation for details of best practices in order to obtain good-quality results.
This method passes the no_record
parameter to the API.
§Examples
use geocoding_async::{Opencage, InputBounds, Point};
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let address = "UCL Centre for Advanced Spatial Analysis";
// Optionally restrict the search space using a bounding box.
// The first point is the bottom-left corner, the second is the top-right.
let bbox = InputBounds::new(
Point::new(-0.13806939125061035, 51.51989264641164),
Point::new(-0.13427138328552246, 51.52319711775629),
);
let res = oc.forward_full(&address, bbox).await.unwrap();
let first_result = &res.results[0];
// the first result is correct
assert!(first_result.formatted.contains("90 Tottenham Court Road"));
// You can pass NOBOX if you don't need bounds.
use geocoding_async::{Opencage, InputBounds, Point};
use geocoding_async::opencage::{NOBOX};
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let address = "Moabit, Berlin";
let res = oc.forward_full(&address, NOBOX).await.unwrap();
let first_result = &res.results[0];
assert_eq!(
first_result.formatted,
"Moabit, Berlin, Germany"
);
// There are several ways to construct a Point, such as from a tuple
use geocoding_async::{Opencage, InputBounds, Point};
let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
let address = "UCL Centre for Advanced Spatial Analysis";
let bbox = InputBounds::new(
(-0.13806939125061035, 51.51989264641164),
(-0.13427138328552246, 51.52319711775629),
);
let res = oc.forward_full(&address, bbox).await.unwrap();
let first_result = &res.results[0];
assert!(
first_result.formatted.contains(
"90 Tottenham Court Road"
));
Trait Implementations§
Source§impl<'a, T> Forward<T> for Opencage<'a>
impl<'a, T> Forward<T> for Opencage<'a>
Source§async fn forward(&self, place: &str) -> Result<Vec<Point<T>>, GeocodingError>
async fn forward(&self, place: &str) -> Result<Vec<Point<T>>, GeocodingError>
A forward-geocoding lookup of an address. Please see the documentation for details of best practices in order to obtain good-quality results.
This method passes the no_annotations
and no_record
parameters to the API.