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

## 對應路段

```python
for link in client.locating.links(121.5155, 25.0766, 50):
    print(link.id, link.road_name, link.bearing)

closest = client.locating.closest_links(
    121.5155, 25.0766, 50, road_class=0, road_name="國道1號", direction="1"
)
by_address = client.locating.links_by_address("臺北市中正區忠孝西路一段3號")
by_mileage = client.locating.links_by_mileage(0, "國道1號", "0", 0.4, 5.3)
```

坐標依序為經度與緯度，範圍以公尺計，上限 500 公尺。`closest_links()` 可另外指定方位、道路分類、道路名稱或道路代碼。

## 路段上的設施

```python
facilities = client.locating.road_facilities("國道1號", road_class=0)

for facility in facilities.facilities:
    print(facility.type, facility.id, facility.link_id)

for station in client.locating.station_links("TRTC"):
    print(station.name, station.exits)
```

單一路段的設施以 `link_facilities()` 查詢。

## 所在位置

```python
print(client.locating.addresses(121.5155, 25.0766)[0].address)
print(client.locating.districts(121.5155, 25.0766)[0].town_name)
print(client.locating.landmarks(121.5155, 25.0766))
print(client.locating.mileages(0, "000010", 121.5155, 25.0766))
```

## 周邊資訊

```python
transit = client.locating.transit(121.5155, 25.0766, radius=300)
print(transit.rail_stations, transit.bus_stops, transit.bike_stations)

tourism = client.locating.tourism(121.5155, 25.0766, 500)
print(tourism.scenic_spots, tourism.restaurants)
```

`transit()` 的範圍為 100 至 500 公尺，`tourism()` 為 100 至 1000 公尺，以 100 公尺為單位。`transit()` 未指定範圍時回傳最近的站點。

| 名稱 | 內容 |
| --- | --- |
| `tourism_by_name` | 指定景點周邊的運輸與觀光資訊 |
| `parking` | 周邊停車場的車位數 |
| `population` | 周邊人口數 |
| `households` | 公車站牌周邊的家戶數 |

所有參數與欄位見[定位服務 API](/reference/locating)。