How to make a route with more than 25 points in the Google Maps API?

Asked

Viewed 107 times

1

I’m developing an application that to make a feature, I need to book bus stops and trace the route to the bus.

I have all stops in an array, each with its latitude and longitude. With the use of the google api I can do absolutely everything I wanted, the route is mapped correctly and goes through the respective points (stops), however have a limit.. If my career has more than 25 stops (waypoints), it is no longer possible to plot the route using waypoints.

Is there any solution to my problem?

/* Inicio e fim da rota */
    var start = busStopList[0].position;
    var end = busStopList[busStopList.length - 1].position;

    /* Array que vai armazenar todos os waypoints */
    var waypts = []
    
    busStopList.forEach(value => {
        /* Inserir no array um objeto com a localização da paragem */
        waypts.push({location: value.position})
    })
    
    /* Eliminar o primeiro e o ultimo item do array */
    waypts.splice(0, 1)
    waypts.splice(waypts.length - 1, 1)

    /* Configs do request */
    var request = {
        origin: start,
        destination: end,
        waypoints: waypts,
        optimizeWaypoints: true,
        travelMode: 'DRIVING'
    };

inserir a descrição da imagem aqui

  • 1

    I found this answer in stackoverflow in English https://stackoverflow.com/questions/8779886/exceed-23-waypoint-per-request-limit-on-google-directions-api-business-work-lev#:~:text=Individual%20directions%20requests%20may%20contain,waypoints%20allowed%20in%20each%20request. I can’t test here if they work.

  • 1

    It really, really helped. Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.