Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based off my <a href="http://www.geocodezip.com/inventoresdegaragem_com_dbteste_indexA.html" rel="nofollow noreferrer">previous example</a> from your <a href="https://stackoverflow.com/questions/11743799/clickable-driving-direction-on-google-maps-v3">earlier question</a></p> <p>This is what you say you want: <a href="http://www.geocodezip.com/inventoresdegaragem_com_dbteste_indexB.html" rel="nofollow noreferrer">working example with multiple routes</a></p> <p><strong>code snippet:</strong></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var map, ren, ser; var data = {}; var data2 = {}; var marker; var infowindow; var doMark = true; var directionsDisplay; var wayA = []; var wayB = []; var directionResult = []; //Função de Inicio function goma() { var mapDiv = document.getElementById('mappy'); var mapOptions = { zoom: 12, center: new google.maps.LatLng(-23.563594, -46.654239), mapTypeId: google.maps.MapTypeId.ROADMAP } //Cria o mapa do google, coloca as definições do mapa, como tipo de visualização, pode ser ROADMAP, SATELLITE, HYBRID, TERRAIN map = new google.maps.Map(mapDiv, mapOptions); var control = document.createElement('DIV'); control.style.padding = '1px'; control.style.border = '1px solid #000'; control.style.backgroundColor = 'white'; control.style.cursor = 'pointer'; control.innerHTML = '&lt;img src="http://i47.tinypic.com/2dlp2fc.jpg" border="0" alt="Image and video hosting by TinyPic"&gt;'; control.index = 1; map.controls[google.maps.ControlPosition.TOP_RIGHT].push(control); google.maps.event.addDomListener(control, 'click', function() { doMark = false; markNow(); }); google.maps.event.addListener(map, "click", function(event) { if (wayA.length == wayB.length) { wayA.push(new google.maps.Marker({ draggable: true, position: event.latLng, map: map })); } else { wayB.push(new google.maps.Marker({ draggable: true, position: event.latLng, map: map })); //Renderiza a rota, o draggable é diz se o waypoint é arrastavel ou não ren = new google.maps.DirectionsRenderer({ 'draggable': true }); ren.setMap(map); ren.setPanel(document.getElementById("directionsPanel")); ser = new google.maps.DirectionsService(); //Cria a rota, o DirectionTravelMode pode ser: DRIVING, WALKING, BICYCLING ou TRANSIT ser.route({ 'origin': wayA[wayA.length - 1].getPosition(), 'destination': wayB[wayB.length - 1].getPosition(), 'travelMode': google.maps.DirectionsTravelMode.DRIVING }, function(res, sts) { if (sts == 'OK') { directionResult.push(res); ren.setDirections(res); } else { directionResult.push(null); } }) } }); } var html = "&lt;table&gt;" + "&lt;tr&gt;&lt;td&gt;Nome:&lt;/td&gt; &lt;td&gt;&lt;input type='text' id='name'/&gt; &lt;/td&gt; &lt;/tr&gt;" + "&lt;tr&gt;&lt;td&gt;Endereco:&lt;/td&gt; &lt;td&gt;&lt;input type='text' id='address'/&gt;&lt;/td&gt; &lt;/tr&gt;" + "&lt;tr&gt;&lt;td&gt;Tipo:&lt;/td&gt; &lt;td&gt;&lt;select id='type'&gt;" + "&lt;option value='oficina' SELECTED&gt;oficina&lt;/option&gt;" + "&lt;option value='restaurante'&gt;restaurante&lt;/option&gt;" + "&lt;/select&gt; &lt;/td&gt;&lt;/tr&gt;" + "&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type='button' value='Salvar' onclick='saveData()'/&gt;&lt;/td&gt;&lt;/tr&gt;"; infowindow = new google.maps.InfoWindow({ content: html }); //Geocoding (pesquisar) function marcar() { var endereco = document.getElementById("endereco").value; //alert(endereco) geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'address': endereco }, function(results, status) { if (status = google.maps.GeocoderStatus.OK) { latlng = results[0].geometry.location; markerInicio = new google.maps.Marker({ position: latlng, map: map }); map.setCenter(latlng); } }); } function markNow() { if (doMark == false) { google.maps.event.addListener(map, "click", function(event) { marker = new google.maps.Marker({ position: event.latLng, map: map }); google.maps.event.addListener(marker, "click", function() { infowindow.open(map, marker); }); }); } } google.maps.event.addDomListener(window, 'load', goma);</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>html, body { height: 100%; width: 100%; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="http://maps.google.com/maps/api/js"&gt;&lt;/script&gt; &lt;div id="mappy" style="float:left;width:70%; height:100%"&gt;&lt;/div&gt; &lt;div id="directionsPanel" style="float:right;width:30%;height 100%"&gt;&lt;/div&gt; &lt;div&gt; &lt;label&gt;Endereco&lt;/label&gt; &lt;input type="text" id="endereco"&gt; &lt;/div&gt; &lt;input type="button" value="Marcar" id="marcar" onClick="marcar()"&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload