592 字
3 分鐘
[地址轉換經緯度]TDX地址轉經緯度小工具(期間限定)

#大量地址轉換經緯度 #TDX #API #python
![[地址轉換經緯度]TDX地址轉經緯度小工具(期間限定)](/wp-content/uploads/2024/04/image-52-1024x566.png)
目前TDX運輸資料流通網可以進行免費試用,其中最高等級的級別提供了約200萬次的高速地址轉經緯度API(2024/06/01為止),筆者提供了教學影片和轉換小工具如下
教學影片:
https://www.youtube.com/watch?v=C9pS0w0XLwQ
TDX地址轉經緯度小工具
如何使用
1.依序輸入Client_ID,Client_secret,以及每秒呼叫次數(參考影片教學)
TDX地址轉換經緯度
fetch("https://tdx.transportdata.tw/auth/realms/TDXConnect/protocol/openid-connect/token", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: `grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}`, }) .then((response) => response.json()) .then((data) => { localStorage.setItem("token", data.access_token); localStorage.setItem("token_timestamp", new Date().toISOString()); alert("Token has been obtained and stored in local storage."); }) .catch((error) => console.error("Error:", error)); }
function clearToken() { localStorage.removeItem("token"); localStorage.removeItem("token_timestamp"); alert("Token has been cleared from local storage."); }
function getCoordinates() { const client_id = document.getElementById("client_id").value; const client_secret = document.getElementById("client_secret").value; const addresses = document .getElementById("addresses") .value.split("\n") .filter((address) => address.trim() !== "");
fetchCoordinates(addresses); }
function fetchCoordinates(addresses) { const token = localStorage.getItem("token"); const requests_per_second = document.getElementById("requests_per_second").value; console.log("每秒最多呼叫:", requests_per_second); addresses.forEach((address) => { setTimeout(() => { fetch(`https://tdx.transportdata.tw/api/advanced/V3/Map/GeoCode/Coordinate/Address/${encodeURIComponent(address)}?format=JSON`, { headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, }) .then((response) => response.json()) .then((data) => { const coordinatesResult = document.getElementById("coordinatesResult"); const match = data[0]?.Geometry?.match(/POINT \(([-+]?\d*\.\d+) ([-+]?\d*\.\d+)\)/); if (match) { const latitude = parseFloat(match[1]); const longitude = parseFloat(match[2]); coordinatesResult.value += `${address}, ${latitude}, ${longitude}\n`; } else { coordinatesResult.value += `Failed to fetch coordinates for ${address}\n`; } }) .catch((error) => { console.error("Error:", error); const coordinatesResult = document.getElementById("coordinatesResult"); coordinatesResult.value += `Failed to fetch coordinates for ${address}\n`; }); }, 1000 / requests_per_second); }); }</script>
https://www.spatialgeolab.com/tips-addresses2lat-lon/
[地址轉換經緯度]TDX地址轉經緯度小工具(期間限定)
https://www.spatialgeolab.com/address-to-latlon-part3/分類導覽
© 2026 GeoLab. All Rights Reserved.
