kinath_ru
kinath_ru

Reputation: 4678

Geting directions to same point through waypoints in Google Maps

Hi I have some locations and a center of a location. I want to set the center location as the origin as well as the destination. I have some waypoints and I want to start from the origin and travel through the way points and return to the origin again. Can anyone help me?

Upvotes: 1

Views: 242

Answers (1)

Vagner Lucas Gomes
Vagner Lucas Gomes

Reputation: 103

Your destination point will have to be the same source

 if (origem == null) {  // origem
                            var lat = document.getElementById("lat").value;
                            var lng = document.getElementById("lng").value;
                            event.LatLng = new google.maps.LatLng(lat, lng); 
                            origem = event.LatLng;
                            addMarkerOrigem(origem);

                    } else if (destino == null) {   // destino
                        var latD = document.getElementById("latInt").value;
                        var lngD = document.getElementById("lngInt").value;
                        event.LatLng = new google.maps.LatLng(latD, lngD);
                        destino = event.LatLng;
                        addMarkerOrigem(destino);

after

 var request = {
                            origin: origem, //define a origem no paramentro do metodo route()
                            destination: origem,//define o destino no parametro do metodo route() 
                            waypoints: waypoints,
                            travelMode: mode, // o modo de gerar o caminho que vem mode = google.maps.DirectionsTravelMode.DRIVING;
                            optimizeWaypoints: true, // variavel true, optimiza o caminho, mostrará sempre o menor custo
                            provideRouteAlternatives: true //exibira rotas alternativas
                            //tem muitas outras propriedades opcionais, obrigatorias são apenas origin destination e travelMode.
                        };

                        directionsService.route(request, function(response, status) {//seta os parametros de requisição e resposta
                            if (status == google.maps.DirectionsStatus.OK) { // se as direções estiverem "OK" ele vai criar a rota
                                directionsDisplay.setDirections(response);
                            }
                        });

                        clearMarkers();
                        directionsVisible = true;
                    }

vai then using the idea of ​​putting the other points of this potos walks between source and destination, and destination = source

origin: origem, //define a origem no paramentro do metodo route() destination: origem,//define o destino no parametro do metodo route()

Upvotes: 1

Related Questions