Skip to main content

Geocoder

Struct Geocoder 

Source
pub struct Geocoder { /* private fields */ }
Expand description

逆ジオコーディングエンジン

国土交通省「位置参照情報」(大字・町丁目レベル)の代表点データを保持し、 座標から最寄りの大字・町丁目を検索します。

§注意

位置参照情報は各町丁目の代表点(ポリゴンではない)のデータです。 検索結果は「代表点が最も近い町丁目」であり、厳密に「その座標を含む町丁目」 とは限りません。町丁目の境界付近では隣の町丁目が返ることがあります。

Implementations§

Source§

impl Geocoder

Source

pub fn new() -> Self

同梱データから構築する

全国の大字・町丁目データ(約19万件)を展開するため、 数十ミリ秒程度かかります。アプリケーションで使い回してください。

Source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self, Error>

データファイルから構築する

embedded-dataフィーチャーを無効にした場合、データファイルは GitHub Releasesから取得するか、tools/build-dataで生成してください。

Source

pub fn from_reader(reader: impl Read) -> Result<Self, Error>

リーダーから構築する

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

圧縮済みデータのバイト列から構築する

Source

pub fn reverse_geocode( &self, lat: f64, lon: f64, ) -> Result<ReverseGeocodeResult<'_>, Error>

座標から最寄りの大字・町丁目を検索する

§エラー

座標が日本のメッシュ範囲(北緯20〜46度、東経122〜154度)の外の場合は Error::OutOfJapanRangeを返します。

§例
use japan_reverse_geocoder::Geocoder;

let geocoder = Geocoder::new();
let result = geocoder.reverse_geocode(35.6812, 139.7671).unwrap();
println!(
    "{}{}{} ({:.0}m)",
    result.address.prefecture, result.address.city, result.address.town,
    result.distance_meters
);
Source

pub fn nearest( &self, lat: f64, lon: f64, k: usize, ) -> Result<Vec<ReverseGeocodeResult<'_>>, Error>

座標に近い順にk件の大字・町丁目を検索する

収録レコード数より大きいkを指定した場合は全件を返します。

Source

pub fn within_radius( &self, lat: f64, lon: f64, radius_meters: f64, ) -> Result<Vec<ReverseGeocodeResult<'_>>, Error>

半径radius_meters以内の大字・町丁目を近い順に列挙する

半径が負・NaNの場合は空のベクターを返します。

Source

pub fn data_version(&self) -> &str

収録データのバージョン表記(例: “19.0b”)

Source

pub fn len(&self) -> usize

収録レコード数

Source

pub fn is_empty(&self) -> bool

レコードが空かどうか

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.