0
I have this code for creating routes using Google Maps
var map;
var directionsDisplay; // Instanciaremos ele mais tarde, que será o nosso google.maps.DirectionsRenderer
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer(); // Instanciando...
var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
var options = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapa"), options);
directionsDisplay.setMap(map); // Relacionamos o directionsDisplay com o mapa desejado
}
initialize();
$("form").submit(function(event) {
event.preventDefault();
var enderecoPartida = $("#txtEnderecoPartida").val();
var enderecoChegada = $("#txtEnderecoChegada").val();
var request = { // Novo objeto google.maps.DirectionsRequest, contendo:
origin: enderecoPartida, // origem
destination: enderecoChegada, // destino
travelMode: google.maps.TravelMode.DRIVING // meio de transporte, nesse caso, de carro
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) { // Se deu tudo certo
directionsDisplay.setDirections(result); // Renderizamos no mapa o resultado
}
});
});
I found this code on the link Blog Princiweb
I need to use the route using coordinates directly, without using Geoprocessing to convert the coordinates to address.
You can pass the lat/lng to the properties
origin
anddestination
, need not necessarily be an address (String). See more in the documentation of Google Maps API.– Douglas Garrido
Thank you Douglas, I was looking for this documentation.
– b3r3ch1t
Okay, I’ll leave that as an answer then. Just mark it as the correct one by doing.
– Douglas Garrido