Distancia

Calcula a distância e o tempo de trajeto entre dois endereços.

Overview

This node calculates the distance and travel time between two addresses. It is useful in scenarios where you need to estimate how far apart two locations are and how long it will take to travel between them, such as route planning, delivery logistics, or travel time estimation.

The node works by first converting the origin and destination addresses into geographic coordinates (longitude and latitude) using a geolocation API. Then, it uses a routing API to calculate the driving distance and duration between these coordinates.

Practical example:

  • A delivery service can input pickup and drop-off addresses to get estimated travel times for scheduling.
  • A real estate app can show distances from a property to key points of interest.

Properties

Name Meaning
Endereço de Origem The starting address for the distance calculation (e.g., "Av. Guarani, 179, Planalto Serrano, Serra").
Endereço de Destino The destination address for the distance calculation (e.g., "Rua Goiabeiras, 234, Vista da Serra II, Serra").
URL da API de Geolocalização 1 The URL of the first geolocation API used to convert addresses into coordinates (e.g., https://nominatim.openstreetmap.org/search).
Chave da API de Geolocalização 1 Optional API key for the first geolocation service if required.
URL da API de Geolocalização 2 The URL of the second geolocation API used to calculate the route distance and duration (e.g., https://api.openrouteservice.org/v2/directions/driving-car).
Chave da API de Geolocalização 2 Required API key for the second geolocation/routing service.

Output

The node outputs a JSON object with the following fields:

  • distanceInMeters: Distance between the two points in meters (number).
  • durationInSeconds: Estimated travel time in seconds (number).
  • distanceInKm: Distance formatted as kilometers with two decimals (string, e.g., "12.34 km").
  • durationInMinutes: Duration formatted as minutes with two decimals (string, e.g., "15.67 min").
  • durationFormatted: Duration formatted as HH:mm:ss (string, e.g., "00:15:40").

No binary data output is produced by this node.

Dependencies

  • Requires access to two external APIs:
    1. A geolocation API that converts addresses to geographic coordinates.
    2. A routing API that calculates distance and duration between coordinates.
  • Requires valid API keys for the routing API and optionally for the geolocation API.
  • The node uses HTTP GET requests via the Axios library to interact with these APIs.
  • Network connectivity and correct API URLs are necessary.

Troubleshooting

  • Common issues:

    • Invalid or incomplete addresses may cause the geolocation API to return no results.
    • Incorrect or missing API keys will result in authentication errors.
    • Wrong API URLs or changes in API endpoints can cause request failures.
    • Rate limits on the APIs might block requests if exceeded.
  • Error messages and resolutions:

    • "Cannot read property 'lon' of undefined": The geolocation API did not return any results for the given address. Verify the address format and correctness.
    • HTTP 401 Unauthorized or 403 Forbidden: Check that the API keys are valid and have the necessary permissions.
    • Network errors or timeouts: Ensure network connectivity and that the API endpoints are reachable.
    • Unexpected response structure: Confirm that the APIs used match the expected response formats.

Links and References

Discussion