Vereis tengo este codigo que me crea una ruta de un lugar a otro la cosa es que necesito que el punto "A" aparezca por defecto y se muestre en el mapa y una vez que se introduzca la direccion "B" y pulsemos ya nos cree la ruta
Aqui esta el codigo:
Código HTML:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>Displaying text directions with <code>setPanel()</code></title> <link href="default.css" rel="stylesheet"> <style> #directions-panel { height: 100%; float: right; width: 390px; overflow: auto; } #map-canvas { margin-right: 400px; } #control { background: #fff; padding: 5px; font-size: 14px; font-family: Arial; border: 1px solid #ccc; box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4); display: none; } @media print { #map-canvas { height: 500px; margin: 0; } #directions-panel { float: none; width: auto; } } </style> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script type="text/javascript"> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var mapOptions = { zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(37.890054, -4.778567) }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directions-panel')); var control = document.getElementById('control'); control.style.display = 'block'; map.controls[google.maps.ControlPosition.TOP_CENTER].push(control); } var start = 'camino de los sastres 1 ,españa'; function calcRoute() { var end = document.getElementById('end').value + ' ,españa'; var request = { origin: start, destination: end, travelMode: google.maps.TravelMode.WALKING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body> <div id="control"> <input type="text" id="start" value=""> <input type="text" id="end" value=""> <button onclick="calcRoute();">enviar</button> </div> <div id="directions-panel"></div> <div id="map-canvas"></div> </body> </html>
Un saludo amigos!!