pub struct ReverseGeocoder { /* private fields */ }Expand description
A local, read-only reverse geocoder.
Implementations§
Source§impl ReverseGeocoder
impl ReverseGeocoder
Sourcepub fn embedded() -> Result<Self, Error>
pub fn embedded() -> Result<Self, Error>
Loads the cn_admin.bin bundled with this crate. No separate data-file
download or local build is needed for ordinary users.
Examples found in repository?
examples/minimal.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let geocoder = ReverseGeocoder::embedded()?;
5
6 // Recorded location : 42°16.9552000'N 126°36.5127000'E 896m
7 let first = geocoder
8 .reverse_geocode_degree_minutes("42°16.9552000'N", "126°36.5127000'E")?
9 .expect("point is in data coverage");
10 println!(
11 "{} {} {} ({})",
12 first.province.name, first.city.name, first.county.name, first.county.code
13 );
14
15 // Recorded location : 22°09.8935000'N 113°33.4033000'E 13m
16 let second = geocoder
17 .reverse_geocode(22.164891666666667, 113.556721666666667).unwrap();
18 println!(
19 "{} {} {} ({})",
20 second.province.name, second.city.name, second.county.name, second.county.code
21 );
22
23 Ok(())
24}Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>
Opens a binary data file generated by build-data.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Loads a binary data file from memory, including one embedded with include_bytes!.
Sourcepub fn reverse_geocode(&self, latitude: f64, longitude: f64) -> Option<Address>
pub fn reverse_geocode(&self, latitude: f64, longitude: f64) -> Option<Address>
Looks up decimal (latitude, longitude) coordinates.
A coordinate outside the bundled China boundaries returns None.
Examples found in repository?
examples/minimal.rs (line 17)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let geocoder = ReverseGeocoder::embedded()?;
5
6 // Recorded location : 42°16.9552000'N 126°36.5127000'E 896m
7 let first = geocoder
8 .reverse_geocode_degree_minutes("42°16.9552000'N", "126°36.5127000'E")?
9 .expect("point is in data coverage");
10 println!(
11 "{} {} {} ({})",
12 first.province.name, first.city.name, first.county.name, first.county.code
13 );
14
15 // Recorded location : 22°09.8935000'N 113°33.4033000'E 13m
16 let second = geocoder
17 .reverse_geocode(22.164891666666667, 113.556721666666667).unwrap();
18 println!(
19 "{} {} {} ({})",
20 second.province.name, second.city.name, second.county.name, second.county.code
21 );
22
23 Ok(())
24}Sourcepub fn reverse_geocode_degree_minutes(
&self,
latitude: &str,
longitude: &str,
) -> Result<Option<Address>, CoordinateParseError>
pub fn reverse_geocode_degree_minutes( &self, latitude: &str, longitude: &str, ) -> Result<Option<Address>, CoordinateParseError>
Looks up degree-minute latitude and longitude, for example
reverse_geocode_degree_minutes("42°16.9552000'N", "126°36.5127000'E").
A valid coordinate outside the bundled China boundaries returns Ok(None).
Invalid coordinate text returns CoordinateParseError.
Examples found in repository?
examples/minimal.rs (line 8)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let geocoder = ReverseGeocoder::embedded()?;
5
6 // Recorded location : 42°16.9552000'N 126°36.5127000'E 896m
7 let first = geocoder
8 .reverse_geocode_degree_minutes("42°16.9552000'N", "126°36.5127000'E")?
9 .expect("point is in data coverage");
10 println!(
11 "{} {} {} ({})",
12 first.province.name, first.city.name, first.county.name, first.county.code
13 );
14
15 // Recorded location : 22°09.8935000'N 113°33.4033000'E 13m
16 let second = geocoder
17 .reverse_geocode(22.164891666666667, 113.556721666666667).unwrap();
18 println!(
19 "{} {} {} ({})",
20 second.province.name, second.city.name, second.county.name, second.county.code
21 );
22
23 Ok(())
24}Auto Trait Implementations§
impl Forget for ReverseGeocoder
impl Freeze for ReverseGeocoder
impl RefUnwindSafe for ReverseGeocoder
impl Send for ReverseGeocoder
impl Sync for ReverseGeocoder
impl Unpin for ReverseGeocoder
impl UnsafeUnpin for ReverseGeocoder
impl UnwindSafe for ReverseGeocoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more