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 57 58 59 60 61 62 63 64 65 66
|
function addInfo(info){
var oDiv = document.getElementById("trajets");
oDiv.innerHTML += info;
}
function ajoutSuccessif(inVilleDep,inVilleArr,inVillesArret,divEcriture) {
idVilleDep = document.getElementById(""+inVilleDep+"").value;
idVilleArr = document.getElementById(""+inVilleArr+"").value;
idVillesArret = document.getElementById(""+inVillesArret+"").value;
$.post("repAjout.php", {idVDep: ""+idVilleDep+"", idVArr: ""+idVilleArr+"", idVarrets: ""+idVillesArret+"", div: ""+divEcriture+""}, function(data){
var i=0;
var total ="";
var traj ="";
var sommeduree=0;
var sommedistance=0;
var res = "";
res = data.split('/');
var length = res.length;
for(i=0;i<length-1;i++){ //pour chaque element de mon tableau 'res'
if (i%6==0){ //si 'i' vaut 0,6,12... alors..
//alert(i); <-- avec ça, ça marche bien..
var vilA = ""+res[i]+"";
var vilB = ""+res[i+1]+"";
var latA = res[i+2];
var longA = res[i+3];
var latB = res[i+4];
var longB = res[i+5];
var map;
var directionsPanel;
var directions;
map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GLargeMapControl3D());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(47.082999, 2.395692), 6);
directionsPanel = document.getElementById("map_directions");
directions = new GDirections(map, directionsPanel);
directions.load("from: "+latA+", "+longA+" to: "+latB+", "+longB);
GEvent.addListener(directions,"load", function(vilA,vilB) {
var distance = directions.getDistance().meters;
distance=Math.floor(distance/1000);
var duree = directions.getDuration().seconds;
var heures=Math.floor(duree/3600);
var minutes=(duree/60)-(heures*60);
minutes=Math.floor(minutes);
addInfo( vilA + " -> " + vilB + " distance : " + distance + "km" + " duree : " + heures + "h" + minutes + "min" + "<br />");
});
}
}
});
} |
Partager