Get Directions Google Map
by XcsN
HTML
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<div id="map" style="width:400px;height:400px;">Google Map</div>
JavaScript
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
/*var waypts = [];
waypts.push({
location:"Buttım, Bursa, Türkiye",
stopover:false
});*/
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
center: new google.maps.LatLng(40.22, 29),
zoom: 11
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
initialize();
var start = "Kent Meydanı, Bursa, Türkiye";
var end = "Haşim İşcan Cd No:42, Tuzpazarı Mh., Bursa, Türkiye";
var request = {
origin: start,
destination: end,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}
calcRoute();