Veran, estoy usando este codigo para crear unas rutas con la api de google maps:.
Código Javascript:
Ver original
<script> var rendererOptions = { draggable: true }; var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);; var directionsService = new google.maps.DirectionsService(); var map; var australia = new google.maps.LatLng(37.888175, -4.779384); function initialize() { var mapOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP, center: australia }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById('directionsPanel')); google.maps.event.addListener(directionsDisplay, 'directions_changed', function() { computeTotalDistance(directionsDisplay.directions); }); calcRoute(); } function calcRoute() { var request = { origin: '<?php echo $or; ?>', destination: '<?php echo $origend; ?>', waypoints:[<?php echo $cadena; ?>], travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } function computeTotalDistance(result) { var total = 0; var myroute = result.routes[0]; for (var i = 0; i < myroute.legs.length; i++) { total += myroute.legs[i].distance.value; } total = total / 1000. document.getElementById('total').innerHTML = '<span style="font-size:30pt;">'. = total + ' km </span>'; } google.maps.event.addDomListener(window, 'load', initialize); </script>
Código HTML:
<link href="default.css" rel="stylesheet"> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=es"></script> <div class="mapa" style="padding-top:13px; "> <div id="map-canvas" style="width:97%; height:400px;"></div> <div id="directionsPanel" style="width:97%;height 100%;"> <p>Distancia Total: <span id="total" class="texto-guia"></span></p> </div>
A ver si alguien conoce esta api sabe como se podria hacer
Un saludo!