Route berechnen
Sehr praktisch ist es, wenn man direkt in der Karte eine Route von oder zum Marker berechnen lassen kann:
Hier der Code dazu:
<script type="text/javascript"> var map = null; function LoadMap() { map = new google.maps.Map(document.getElementById('karte'), { center: new google.maps.LatLng(52.5162731, 13.3777642), zoom: 16, mapTypeId: google.maps.MapTypeId.HYBRID, scaleControl: true, overviewMapControl: true, overviewMapControlOptions:{opened:true}, }); var marker = new google.maps.Marker( { position: new google.maps.LatLng(52.5162731, 13.3777642), map: map, title: 'Ein Marker' }); var sContent = '<h1 style="margin-top:0px;">Router hierher berechnen</h1>'; sContent += '<form onsubmit="route(false); return false;">'; sContent += 'Von: <input type="text" size=40 maxlen=40 name="daddr" id="daddr" value="" style="width:200px;">'; sContent += '<div><a href="javascript:route(true);">Los</a></div>'; sContent += '<div><a href="javascript:route(false);">In neuem Fenster öffnen</a></div>'; sContent += '</form>'; var infoWindow = new google.maps.InfoWindow( { content: '<div style="min-height:60px; min-width:260px;">'+sContent+'</div>', }); infoWindow.open(map, marker); } var directionsService = new google.maps.DirectionsService(); var directionsDisplay = new google.maps.DirectionsRenderer(); function route(bSameWindow) { if (bSameWindow) { directionsService.route( { origin: document.getElementById("daddr").value, destination: new google.maps.LatLng(52.5162731, 13.3777642), travelMode: google.maps.TravelMode.DRIVING }, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setMap(map); directionsDisplay.setDirections(response); } }); } else { window.open("http://maps.google.de/maps?saddr=52.5162731,13.3777642"+"&daddr="+document.getElementById("daddr").value, '_blank'); } } </script>