Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Apps Script Google Direction API - arrival_stop returning ERROR

I am trying to return arrival_stop.name from Google directions API in an Apps Script function. Here is my code:

const GOOGLEMAPS_STEPS_TRANSIT_DETAILS = (origin, destination, mode = 'transit') => {
  const { routes = [] } = Maps.newDirectionFinder()
    .setOrigin(origin)
    .setDestination(destination)
    .setMode(mode)
    .getDirections();
  if (!routes.length) {
    throw new Error('No route found!');
  }

  var stepTransitDetails = routes
    .map(({ legs }) => {
      return legs.map(({ steps }) => {
        return steps.map((step) => {
          return step.transit_details.arrival_stop.name;
        });
      });
    })
    .join(' , ');

  return stepTransitDetails;
};

Error given:

TypeError: Cannot read property 'arrival_stop' of undefined (line 228).

Desired output is a list of stops within the transit step - for example if the step is taking the Piccadilly Line train from Leicester Square to Kings Cross the output would be the list of stations it will stop at.

I have this same code working when returning step.html_instructions rather than step.transit_details.arrival_stop.name and if I remove the .arrival_stop.name it returns [object Object],,object Object], meaning it's recognising the steps which involve transit, but adding the .arrival_stop gives an error.

Working based on Google API Docs

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When I saw the data of routes, it seems that there are objects without including the property of transit_details in step. I thought that this might be the reason for your issue. If you want to retrieve step.transit_details.arrival_stop.name, how about the following modification?

From:

var stepTransitDetails = routes
  .map(({ legs }) => {
    return legs.map(({ steps }) => {
      return steps.map((step) => {
        return step.transit_details.arrival_stop.name;
      });
    });
  })
  .join(' , ');

To:

var stepTransitDetails = routes
  .map(({ legs }) => {
    return legs.map(({ steps }) => {
      return steps.filter(({ transit_details }) => transit_details).map(({ transit_details }) => {
        return transit_details.arrival_stop.name;
      });
    });
  })
  .join(' , ');
  • In this modification, filter is used for retrieving the object including transit_details.

Reference:

  • filter()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda