Google Directions API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 Google Directions API 解決 TSP 問題
即使沒有 TSP,Google 也提供解決方式
下載 OR 工具如果您擁有 Google Directions API 金鑰,
看看有哪些是實際地點的 TSP,
Directions API
,提供網址中的位置,並以 JSON 形式取得回應。
您需要自己的
free Directions API 金鑰
或用於商業用途的企業金鑰
舉例來說,這個網址可以用來尋找簡短的葡萄酒製作導覽
這些區域是從阿德萊德開始如果要在
請將網址結尾的 API_KEY 換成您的金鑰。
https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY
結果將會是詳細說明解決方案的長 JSON 回應,其中顯示
Google 地圖路線規劃:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : -33.8347115,
"lng" : 140.8547058
},
"southwest" : {
"lat" : -37.3511758,
"lng" : 138.4951576
}
},
"copyrights" : "Map data ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "139 km",
"value" : 139119
},
"duration" : {
"text" : "1 hour 51 mins",
"value" : 6648
},
"end_address" : "Clare SA 5453, Australia",
"end_location" : {
"lat" : -33.8333395,
"lng" : 138.6117283
},
"start_address" : "Adelaide SA, Australia",
"start_location" : {
"lat" : -34.9285894,
"lng" : 138.5999429
},
"steps" : [
{
"distance" : {
"text" : "70 m",
"value" : 70
},
"duration" : {
"text" : "1 min",
"value" : 6
},
"end_location" : {
"lat" : -34.9285338,
"lng" : 138.6007031
},
"html_instructions" : "Head \u003cb\u003eeast\u003c/b\u003e on \u003cb\u003eReconciliation Plaza\u003c/b\u003e toward \u003cb\u003eVictoria Square\u003c/b\u003e",
...
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-09 (世界標準時間)。
[null,null,["上次更新時間:2024-08-09 (世界標準時間)。"],[[["\u003cp\u003eGoogle Directions API can be used to solve Traveling Salesperson Problems (TSPs) for real-world locations without needing OR-Tools.\u003c/p\u003e\n"],["\u003cp\u003eThis requires a Google Directions API key, obtainable for free for development or as an enterprise key for commercial purposes.\u003c/p\u003e\n"],["\u003cp\u003eBy providing locations within a structured URL, the API returns a JSON response detailing the optimal route and directions.\u003c/p\u003e\n"],["\u003cp\u003eThe response includes comprehensive information like distances, durations, and step-by-step navigation instructions.\u003c/p\u003e\n"]]],["The Google Directions API can solve Traveling Salesperson Problems (TSPs) for real-world locations. Users must obtain a Directions API key. By constructing a URL with locations as waypoints, the API returns a JSON response containing the optimized route. For example, a URL can be created to find a route between winemaking regions in South Australia starting in Adelaide. The returned JSON provides detailed directions for the solution, including distance, duration, and specific steps.\n"],null,["# Google Directions API\n\nSolving TSPs with the Google Directions API\n-------------------------------------------\n\nGoogle also provides a way to solve simple TSPs of real-world locations without\ndownloading OR-Tools. If you have a Google Directions API key, you can solve\nTSPs of real-world locations with the\n[Directions API](https://developers.google.com/maps/documentation/directions/#Waypoints)\n, providing the locations in a URL and getting the response back as JSON.\nYou'll need your own\n[free Directions API key](https://developers.google.com/maps/pricing-and-plans/)\nfor development, or an enterprise key for commercial use.\n\nAs an example, here's a URL that can be used to find a short tour of winemaking\nregions in South Australia, beginning in Adelaide. If you want to try this from\nyour browser, replace *API_KEY* at the end of the URL with your key. \n\n```\nhttps://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY\n```\n\nThe result will be a long JSON response detailing the solution, complete with\nGoogle Maps directions: \n\n```carbon\n{\n \"routes\" : [\n {\n \"bounds\" : {\n \"northeast\" : {\n \"lat\" : -33.8347115,\n \"lng\" : 140.8547058\n },\n \"southwest\" : {\n \"lat\" : -37.3511758,\n \"lng\" : 138.4951576\n }\n },\n \"copyrights\" : \"Map data ©2014 Google\",\n \"legs\" : [\n {\n \"distance\" : {\n \"text\" : \"139 km\",\n \"value\" : 139119\n },\n \"duration\" : {\n \"text\" : \"1 hour 51 mins\",\n \"value\" : 6648\n },\n \"end_address\" : \"Clare SA 5453, Australia\",\n \"end_location\" : {\n \"lat\" : -33.8333395,\n \"lng\" : 138.6117283\n },\n \"start_address\" : \"Adelaide SA, Australia\",\n \"start_location\" : {\n \"lat\" : -34.9285894,\n \"lng\" : 138.5999429\n },\n \"steps\" : [\n {\n \"distance\" : {\n \"text\" : \"70 m\",\n \"value\" : 70\n },\n \"duration\" : {\n \"text\" : \"1 min\",\n \"value\" : 6\n },\n \"end_location\" : {\n \"lat\" : -34.9285338,\n \"lng\" : 138.6007031\n },\n \"html_instructions\" : \"Head \\u003cb\\u003eeast\\u003c/b\\u003e on \\u003cb\\u003eReconciliation Plaza\\u003c/b\\u003e toward \\u003cb\\u003eVictoria Square\\u003c/b\\u003e\",\n...\n```"]]