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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>ViaMichelin JavaScript API V2 - Calculate a distance matrix</title>
<style type="text/css">
table{border-collapse:collapse}
th{background-color:#9ff}
</style>
</head>
<body onload="fLoadMatrix()">
<h2>Distance Matrix with 'Recommanded by Michelin' itinerary type</h2>
<div id="results"></div>
<script src="http://apijsv2.viamichelin.com/apijsv2/api/js?key=JSV2GP20121203183924043982118609$165380&lang=fra" type="text/javascript"></script>
<script type="text/javascript">
var addresses = [
{htm:"BG",lon:"05.270804",lat:"45.798583"},
{htm:"BL",lon:"-0.690042",lat:"45.256747"},
{htm:"BV",lon:"02.878217",lat:"47.510521"},
{htm:"CA",lon:"06.229280",lat:"49.414254"},
{htm:"CH",lon:"00.167677",lat:"47.228748"},
{htm:"CS",lon:"04.754117",lat:"44.632049"},
{htm:"CV",lon:"00.658053",lat:"46.452490"},
{htm:"CZ",lon:"04.794829",lat:"50.090918"},
{htm:"DA",lon:"02.520650",lat:"47.734250"},
{htm:"FH",lon:"07.562887",lat:"47.904414"},
{htm:"FL",lon:"-1.880390",lat:"49.537672"},
{htm:"GF",lon:"00.845718",lat:"44.107986"},
{htm:"GR",lon:"02.136628",lat:"51.014815"},
{htm:"GN",lon:"05.790217",lat:"45.208066"},
{htm:"NO",lon:"03.516924",lat:"48.516606"},
{htm:"PA",lon:"00.634601",lat:"49.860538"},
{htm:"PY",lon:"01.213532",lat:"49.978110"},
{htm:"SA",lon:"04.754564",lat:"45.403929"},
{htm:"SB",lon:"01.578910",lat:"47.719916"},
{htm:"TN",lon:"04.732130",lat:"44.330958"},
];
function fLoadMatrix(){
var out = "<table border='1'><tr><td> </td>";
for(var i=0; i < addresses.length; ++i){
out += "<th>" + addresses[i].htm + "</th>";
}
out += '</tr>';
for(i=0; i < addresses.length; ++i){
out += "<tr><th>" + addresses[i].htm + "</th>";
for(var j=0; j < addresses.length; ++j) {
out += "<td id='"+ i + '_' + j +"'> </td>";
}
out += "</tr>";
}
out += '</table>';
$_id("results").innerHTML = out;
//on run le tableau
for(i=0; i < addresses.length; ++i){
for(j=i+1; j < addresses.length; ++j) {
getInfos(addresses[i].lon, addresses[i].lat, addresses[j].lon, addresses[j].lat,i, j);
//document.write(addresses[i].lon+'<br>'+addresses[i].lat+'<br>'+addresses[j].lon+'<br>'+addresses[j].lat+'<br>'+i+'<br>'+j+'<br>');
}
}
};//fLoadMatrix
function getInfos(coordsAlon, coordsAlat, coordsBlon, coordsBlat, i, j){
VMLaunch("ViaMichelin.Api.Itinerary", {
steps:[//Array of Geo coodinates
{coords: {lon:coordsAlon, lat:coordsAlat}}, //{coords: {lon: 2.24344, lat: 48.83381}}
{coords: {lon:coordsBlon, lat:coordsBlat}}
],
//favMotorways: true,
data: ViaMichelin.Api.Constants.Itinerary.DATA.HEADER
},{
onSuccess : function (result) {
$_id(i + '_' + j).innerHTML = Math.round(result.header.summaries[0].totalTime/60);
$_id(j + '_' + i).innerHTML = Math.round(result.header.summaries[0].totalDist/1000);
},
onError : function (error) {
alert('Whoops! ' + error);
}});
};//getInfos
</script>
</body>
</html> |