8
n8n 中文网amn8n.com

🚚 使用 Open Route API 估算驾驶时间和距离

中级

这是一个AI, IT Ops领域的自动化工作流,包含 9 个节点。主要使用 Set, Wait, HttpRequest, GoogleSheets, ManualTrigger 等节点,结合人工智能技术实现智能自动化。 🚚 使用 Open Route API 估算物流驾驶时间和距离

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "xcH7MXYzo44y7L7X",
  "meta": {
    "instanceId": "",
    "templateCredsSetupCompleted": true
  },
  "name": "🚚 使用 Open Route API 估算驾驶时间和距离",
  "tags": [],
  "nodes": [
    {
      "id": "ce1b3c7f-315a-4714-b616-ecdd9804ee78",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        420,
        -20
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "5a36857f-6b42-4a5b-af68-d2cfaf00ddd3",
      "name": "提取结果",
      "type": "n8n-nodes-base.set",
      "position": [
        980,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4d0acd1a-c049-4353-9fb7-8eb08c138b9c",
              "name": "distance",
              "type": "string",
              "value": "={{ $json.features[0].properties.segments[0].distance }}"
            },
            {
              "id": "2a6ff46a-f620-4dad-a60a-018b8add76d5",
              "name": "duration",
              "type": "string",
              "value": "={{ $json.features[0].properties.segments[0].duration }}"
            },
            {
              "id": "de20932f-4eb5-4372-ad6d-64679df104cb",
              "name": "n_steps",
              "type": "number",
              "value": "={{ $json.features[0].properties.segments[0].steps.length }}"
            },
            {
              "id": "540df5ea-cf63-47cc-8d63-3d6fcac825af",
              "name": "",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "39a779dd-455b-4502-b17f-8c86d6e47e45",
      "name": "请求 Open Route API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        740,
        0
      ],
      "parameters": {
        "url": "https://api.openrouteservice.org/v2/directions/driving-hgv",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": ""
            },
            {
              "name": "start",
              "value": "={{ $json.longitude_departure }}, {{ $json.latitude_departure }}"
            },
            {
              "name": "end",
              "value": "={{ $json.longitude_destination }}, {{ $json.latitude_destination }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json; charset=utf-8"
            },
            {
              "name": "Accept",
              "value": "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "578e34fd-8804-454b-b6be-25d534eb4283",
      "name": "收集路线",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        60,
        -20
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": "Distance"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1NLNviRoVMEj2z78KiueruB5sd2CnvAb80DS7J2melVs",
          "cachedResultUrl": "",
          "cachedResultName": "Open Route Service"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "89320458-8aa8-4faf-8009-0f65899762e1",
      "name": "保存结果",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1200,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $('Loop Over Items').item.json.id }}",
            "n_steps": "={{ $json.n_steps }}",
            "distance": "={{ $json.distance }}",
            "duration": "={{ $json.duration }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "city_departure",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "city_departure",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "longitude_departure",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "longitude_departure",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "latitude_departure",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "latitude_departure",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "city_destination",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "city_destination",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "longitude_destination",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "longitude_destination",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "latitude_destination",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "latitude_destination",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "distance",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "distance",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "duration",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "duration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "n_steps",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "n_steps",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": ""
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.6
    },
    {
      "id": "7f83e93e-a759-4724-8978-5de0f565b17d",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -440
      ],
      "parameters": {
        "color": 7,
        "width": 540,
        "height": 640,
        "content": "### 1. 触发工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "0dd453dd-2a7e-4039-a15d-2936a8ad4d44",
      "name": "当点击\"测试工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -160,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "45b1dc8a-ed85-424f-89f6-656861b118b6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        -440
      ],
      "parameters": {
        "color": 7,
        "width": 1240,
        "height": 640,
        "content": "### 2. 循环收集所有驾驶距离和时间"
      },
      "typeVersion": 1
    },
    {
      "id": "11232056-fc3b-422c-b569-8a4fc9250633",
      "name": "5 秒",
      "type": "n8n-nodes-base.wait",
      "position": [
        1420,
        0
      ],
      "webhookId": "1c5df276-94b5-42b8-9748-634e389cadcf",
      "parameters": {},
      "typeVersion": 1.1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "91a86656-7afe-4e84-921d-3361c4114016",
  "connections": {
    "5 sec": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Results": {
      "main": [
        [
          {
            "node": "5 sec",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Routes": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Results": {
      "main": [
        [
          {
            "node": "Save Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Request Open Route API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Open Route API": {
      "main": [
        [
          {
            "node": "Extract Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Collect Routes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 人工智能, IT 运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量9
分类2
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Samir Saci

Samir Saci

@samirsaci

Automation, AI and Analytics for Supply Chain & Business Optimization Helping businesses streamline operations using n8n, AI agents, and data science to enhance efficiency and sustainability. Linkedin: www.linkedin.com/in/samir-saci

外部链接
在 n8n.io 查看

分享此工作流