1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var maCarte;
var geocoder;
var myOptions;
function initialize() {
geocoder = new google.maps.Geocoder();
directionsDisplay = new google.maps.DirectionsRenderer();
var latlng = new google.maps.LatLng(0,0);
myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
maCarte = new google.maps.Map(document.getElementById("EmplacementDeMaCarte"), myOptions);
var requeteItineraire = {
origin: "monAdresse1",
destination: "monAdresse2",
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'Toto is here !!' +
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
directionsService.route(requeteItineraire, function(response, dirstatus) {
if (dirstatus == google.maps.DirectionsStatus.OK) {
var address = "monAdresse3";
geocoder.geocode( { 'address': address}, function(results, geostatus) {
if (geostatus == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: maCarte,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(maCarte,marker);
});
} else {
alert("Geocode was not successful for the following reason: " + geostatus);
}
});
directionsDisplay.setMap(maCarte);
directionsDisplay.setPanel(document.getElementById("EmplacementItineraireTexte"));
directionsDisplay.setDirections(response);
} else {
alert("Direction was not successful for the following reason: " + dirstatus);
}
});
} |
Partager