互動式折線編碼器公用程式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google 地圖可根據兩個以上的經緯度座標產生簡單的折線。
進一步瞭解折線編碼、簡單折線和複雜折線。
您可以使用這項公用程式,在地圖上互動式產生折線編碼,或輸入座標。
您也可以反向使用這項工具,將折線解碼為座標。
不過,如果您已有編碼折線或座標清單 (以 GeoJSON LineString 形式),並想在地圖上查看折線,請使用互動式折線解碼器公用程式。
在地圖上以互動方式建立折線
- 輸入地址、郵遞區號、地點或地標,將地圖置中,然後按一下「搜尋」。
- 按一下地圖,放置代表折線起點的標記。
- 標記的座標會顯示在「緯度」和「經度」方塊中。
- 按一下「新增地點」按鈕。
這會將座標新增至「位置清單」,並在「編碼折線」方塊中產生編碼。
- 繼續在地圖上放置標記,將折線上的所有位置新增至「位置清單」和「編碼折線」。
編輯座標
- 如要刪除位置,請在「位置清單」中選取該位置,然後按下「刪除所選位置」。
- 如要刪除所有地點並重新開始,請按一下「刪除所有地點」。
- 你無法編輯地點。如要編輯地點,請刪除並重新新增。
如果該位置並非清單結尾,請刪除該位置和後續所有位置。
輸入座標來建立折線
- 如果您已有座標清單,可以手動在對應的方塊中輸入緯度和經度,不必放置標記。
將折線解碼為座標
- 在「Encoded Polyline」(編碼折線) 方塊中輸入折線。
- 如果折線含有逸出字元,請按一下核取方塊取消逸出。
- 按一下「Decode Polyline」(解碼折線)。
座標會顯示在「位置清單」中,地圖上也會繪製線條。
這項公用程式使用 Maps JavaScript API。具體來說,路徑的編碼和解碼作業是由 google.maps.geometry.encoding
命名空間中的靜態方法 encodePath()
和 decodePath()
處理。如要瞭解編碼方式,請參閱「編碼折線演算法格式」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Interactive Polyline Encoder Utility\n\nGoogle Maps can generate a simple polyline from two or more latitude/longitude coordinates.\nLearn more about\n[polyline encoding](/maps/documentation/utilities/polylinealgorithm),\n[simple polylines](/maps/documentation/javascript/examples/polyline-simple),\nand\n[complex polylines](/maps/documentation/javascript/examples/polyline-complex).\n\nWith this utility, you can generate polyline encodings\ninteractively on a map or by entering coordinates.\nYou can also decode polylines into coordinates\nby using this tool in reverse.\n\nHowever, if you have an existing encoded polyline or a list of coordinates as a\n[GeoJSON linestring](https://geojson.org/)\nand want to view the polyline on a map, use the\n[Interactive polyline decoder utility](/maps/documentation/routes/polylinedecoder).\n\n**Create a polyline interactively on the map**\n\n1. Enter an address, zip code, location, or landmark to center the map and click **Search**.\n2. Click the map to place a marker that represents the start location of your polyline.\n3. The coordinates of your marker show in the **Latitude** and **Longitude** boxes.\n4. Click the **Add Location** button. This adds the coordinates to the **Location list** and generates an encoding in the **Encoded Polyline** box.\n5. Continue to place markers on the map to add all locations on your polyline to the **Location list** and the **Encoded polyline**.\n\n**Editing coordinates**\n\n- To delete a location, select it in the **Location list** and press **Delete Selected Location**.\n- To delete all locations and start over, click **Delete All Locations**.\n- You cannot edit locations. To edit a location, delete and re-add it. If the location is not at the end of your list, delete the location and all the ones following.\n\n**Create a polyline by entering coordinates**\n\n- If you have an existing list of coordinates, instead of placing markers, you can manually enter the latitudes and longitudes in their respective boxes.\n\n**Decode a polyline into coordinates**\n\n1. Enter your polyline into the **Encoded Polyline** box.\n2. If your polyline contains escaped characters, click the checkbox to unescape them.\n3. Click **Decode Polyline** . The coordinates show in the **Location list**, and the line is drawn on the map.\n\n\u003cbr /\u003e\n\n|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------|\n| Input an address to center the map: Search | |------------|---| | Latitude: | | | Longitude: | | | | | || \u003cbr /\u003e **Locations list** |\n| |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | | **Warning**: Special characters in the encoded polylines returned in JSON responses are escaped. To use these polylines here you must unescape them. | | Encoded Polyline: | |---------------------------------------------------------------------------------| | | | Unescape special characters in the encoded polylines returned in JSON responses | | | || ||\n\nThis utility uses the Maps JavaScript API. Specifically,\nencoding and decoding of paths are handled by the static methods `encodePath()`\nand `decodePath()` in the `google.maps.geometry.encoding` namespace.\nSee the [Encoded Polyline Algorithm\nFormat](/maps/documentation/utilities/polylinealgorithm) for information about the encoding scheme."]]