# 定位服務 (https://nolantw.github.io/tdx/reference/locating/)

## `Locating`

### `links`

```python
def links(
    longitude: float,
    latitude: float,
    radius: int,
    *,
    cache_ttl: float | None = None,
) -> Records[RoadLink]
```

查詢範圍內的路段，單位為公尺。

### `closest_links`

```python
def closest_links(
    longitude: float,
    latitude: float,
    radius: int,
    *,
    bearing: str | None = None,
    road_class: LinkRoadClass | None = None,
    road_name: str | None = None,
    road_id: str | None = None,
    direction: str | None = None,
    cache_ttl: float | None = None,
) -> Records[RoadLink]
```

查詢最近的路段，可指定方位或道路。

### `links_by_mileage`

```python
def links_by_mileage(
    road_class: LinkRoadClass,
    road_name: str,
    direction: str,
    start: float,
    end: float,
    *,
    cache_ttl: float | None = None,
) -> Records[RoadLinkMatch]
```

查詢道路兩個里程之間的路段，單位為公里。

### `links_by_address`

```python
def links_by_address(
    address: str,
    *,
    same_road: bool = False,
    cache_ttl: float | None = None,
) -> Records[AddressLink]
```

查詢地址鄰近的路段，或僅查詢路名相同的路段。

### `station_links`

```python
def station_links(
    operator: str | None = None,
    *,
    name: str | None = None,
    cache_ttl: float | None = None,
) -> Records[StationLinks]
```

查詢車站出入口對應的路段，可指定 TRTC 等營運單位或車站名稱。

### `link_facilities`

```python
def link_facilities(
    link_id: str,
    *,
    cache_ttl: float | None = None,
) -> RoadFacilities
```

查詢路段的設施。

### `road_facilities`

```python
def road_facilities(
    name: str,
    *,
    road_class: LinkRoadClass | None = None,
    city: City | str | None = None,
    cache_ttl: float | None = None,
) -> RoadFacilities
```

查詢指定道路分類或縣市的道路設施。

### `transit`

```python
def transit(
    longitude: float,
    latitude: float,
    *,
    radius: int | None = None,
    cache_ttl: float | None = None,
) -> NearbyTransit
```

查詢範圍內的公共運輸，單位為公尺，未指定時查詢最近者。

### `tourism`

```python
def tourism(
    longitude: float,
    latitude: float,
    radius: int,
    *,
    cache_ttl: float | None = None,
) -> NearbyTourism
```

查詢範圍內的運輸與觀光資訊，單位為公尺。

### `tourism_by_name`

```python
def tourism_by_name(
    scenic_spot: str,
    *,
    cache_ttl: float | None = None,
) -> NearbyTourism
```

查詢景點周邊的運輸與觀光資訊。

### `parking`

```python
def parking(
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> NearbyParking
```

查詢周邊的停車場。

### `population`

```python
def population(
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> NearbyPopulation
```

查詢周邊人口數。

### `households`

```python
def households(
    stop_uid: str,
    *,
    cache_ttl: float | None = None,
) -> NearbyHouseholds
```

查詢公車站牌周邊的家戶數。

### `addresses`

```python
def addresses(
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> Records[LocatedAddress]
```

查詢位置的地址。

### `mileages`

```python
def mileages(
    road_class: LinkRoadClass,
    road_id: str,
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> Records[LocatedMileage]
```

查詢位置在公路上的里程。

### `landmarks`

```python
def landmarks(
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> Records[LocatedLandmark]
```

查詢鄰近的地標。

### `districts`

```python
def districts(
    longitude: float,
    latitude: float,
    *,
    cache_ttl: float | None = None,
) -> Records[LocatedDistrict]
```

查詢位置所在的縣市與鄉鎮市區。

## `RoadLinkMatch`

```python
class RoadLinkMatch(RoadLink):
    confidence: str | None
```

里程範圍內的路段與比對信心。

## `AddressLink`

```python
class AddressLink(LinkReference):
    road_name_id: str | None
    road_class_name: str | None
    city_id: str | None
    city_name: str | None
    city: str | None
    address: str | None
    length: float | None
    notes: str | None
```

鄰近地址的路段。

## `StationExitLink`

```python
class StationExitLink(BaseModel):
    name: str | None
    note: str | None
    longitude: float | None
    latitude: float | None
    link_id: str | None
    road_id: str | None
    road_name: str | None
    bearing: str | None
```

車站出入口對應的路段。

## `StationLinks`

```python
class StationLinks(BaseModel):
    uid: str
    name: str | None
    city: str | None
    exits: tuple[StationExitLink, ...]
    version: str | None
    updated_on: MaybeDate
```

車站各出入口對應的路段。

## `RoadFacility`

```python
class RoadFacility(BaseModel):
    id: str
    type: str
    authority_code: str | None
    longitude: float | None
    latitude: float | None
    link_id: str | None
    direction: str | None
    city_name: str | None
    city_code: str | None
```

路旁的站牌、偵測器、攝影機或其他設施。

## `RoadFacilities`

```python
class RoadFacilities(BaseModel):
    link_id: str | None
    road_name: str | None
    direction: str | None
    city_name: str | None
    city_code: str | None
    version: str | None
    updated_on: MaybeDate
    facilities: tuple[RoadFacility, ...]
```

道路或路段的設施。

## `NearbyStation`

```python
class NearbyStation(_Located):
    uid: str
    name: str | None
```

周邊的軌道車站或自行車站。

## `NearbyBusStop`

```python
class NearbyBusStop(_Located):
    uid: str
    name: str | None
    route_uid: str | None
    route_name: str | None
    subroute_uid: str | None
    subroute_name: str | None
```

周邊一條公車路線的站牌。

## `NearbyCarPark`

```python
class NearbyCarPark(_Located):
    id: str | None
    name: str | None
```

周邊的停車場或路邊車位。

## `NearbyScenicSpot`

```python
class NearbyScenicSpot(_Located):
    id: str
    name: str | None
```

周邊的景點。

## `NearbyHotel`

```python
class NearbyHotel(_Located):
    id: str
    name: str | None
```

周邊的旅宿。

## `NearbyRestaurant`

```python
class NearbyRestaurant(_Located):
    id: str
    name: str | None
```

周邊的餐飲。

## `NearbyTransit`

```python
class NearbyTransit(BaseModel):
    updated_on: MaybeDate
    rail_stations: tuple[NearbyStation, ...]
    bus_stops: tuple[NearbyBusStop, ...]
    bike_stations: tuple[NearbyStation, ...]
```

周邊的公共運輸。

## `NearbyTourism`

```python
class NearbyTourism(NearbyTransit):
    car_parks: tuple[NearbyCarPark, ...]
    scenic_spots: tuple[NearbyScenicSpot, ...]
    hotels: tuple[NearbyHotel, ...]
    restaurants: tuple[NearbyRestaurant, ...]
```

周邊的公共運輸、停車、景點與旅宿餐飲。

## `SpaceCount`

```python
class SpaceCount(BaseModel):
    type: int
    count: int
```

一種車位的數量。

## `CarParkSpaces`

```python
class CarParkSpaces(BaseModel):
    id: str | None
    name: str | None
    type: int | None
    total: int | None
    spaces: tuple[SpaceCount, ...]
```

停車場的車位。

## `NearbyParking`

```python
class NearbyParking(BaseModel):
    updated_on: MaybeDate
    total: int
    car_parks: tuple[CarParkSpaces, ...]
```

周邊的停車場。

## `StatisticalArea`

```python
class StatisticalArea(BaseModel):
    type: str
    id: str
```

統計人口的區域。

## `NearbyPopulation`

```python
class NearbyPopulation(BaseModel):
    updated_on: MaybeDate
    surveyed_on: MaybeDate
    total: int
    areas: tuple[StatisticalArea, ...]
```

周邊人口數與統計區域。

## `TownHouseholds`

```python
class TownHouseholds(BaseModel):
    county_name: str
    town_code: str
    town_name: str
    count: int
```

鄉鎮市區的家戶數。

## `NearbyHouseholds`

```python
class NearbyHouseholds(BaseModel):
    updated_on: MaybeDate
    surveyed_on: MaybeDate
    total: int
    towns: tuple[TownHouseholds, ...]
```

站牌周邊的家戶數。

## `LocatedAddress`

```python
class LocatedAddress(BaseModel):
    address: str
    geometry: str | None
```

位置的地址，線型為 WKT。

## `LocatedMileage`

```python
class LocatedMileage(BaseModel):
    road_class_name: str | None
    road_name: str | None
    mileage: str
    geometry: str | None
```

位置在道路上的里程，線型為 WKT。

## `LocatedLandmark`

```python
class LocatedLandmark(BaseModel):
    name: str
    distance: float | None
    geometry: str | None
```

鄰近的地標，線型為 WKT。

## `LocatedDistrict`

```python
class LocatedDistrict(BaseModel):
    city: str | None
    city_name: str | None
    town_code: str | None
    town_name: str | None
```

位置所在的縣市與鄉鎮市區。