Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
-.-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Directions service</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var berlin = new google.maps.LatLng(52.5192, 13.4060);
var mapOptions = {
zoom:12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: berlin
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
}
//emulierter json route input
var myRoute = ["52.5192, 13.4060", "52.521705, 13.379888", "52.531705, 13.389888"];
var waypts = [];
for (i=1; i< (myRoute.length - 1); i++){
waypts.push({location:myRoute[i], stopover:true});
}
function calcRoute() {
var start = new google.maps.LatLng(52.5192, 13.4060);
var end = new google.maps.LatLng(52.531705, 13.389888);
var request = {
origin:start,
destination:end,
waypoints:waypts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
// 2. - x. Route durch zweites directionsDisplay & Renderer (siehe http://jsfiddle.net/Lqcde/3/)
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="panel">
<!-- später onload ausführen -->
<button onclick="calcRoute()">Start</button>
</div>
<div id="map-canvas"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment