Bonjour, dans le cadre de mon stage je dois réaliser un projet qui calcul le temps de trajet entre deux lieux. jusque là ça va. J'ai voulu m'aider de cet exemple fourni par le site
https://api.viamichelin.fr/ . Le problème est que je n'ai pas la clé d'accès puisque le formulaire est désactivé. J'ai quand même essayé avec la clé fournie en exemple. Mais cela ne fonctionne pas et ça fait quand même quelques jours que j'essaye de trouver la solution.
voici mon code :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="test._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test</title>
<script src="https://api.viamichelin.com/services/api-js/ " type="text/javascript"></script>
<script type="text/javascript">
/* Insérez ici votre clé */
VMAPI.registerKey("JSBS20070201123465789");
VMAPI.setLanguage("fra")
/* Transformer l'adresse de départ, donnée par l'utilisateur, en un point géocodé */
function search_start_location(){
document.getElementById('result_action').style.display = 'none';
document.getElementById('youritidiv').style.display = 'none';
Start_geocoder = new VMGeocoder();
Start_myaddress = new VMAddress();
var elements_formulaires =
document.forms['itisearch_form'].elements;
Start_myaddress.address = elements_formulaires['form_Start_address'].value;
Start_myaddress.zipCode = elements_formulaires['form_Start_CP'].value;
Start_myaddress.city = elements_formulaires['form_Start_city'].value;
Start_myaddress.countryVMCode = elements_formulaires['form_Start_country'].value;
Start_geocoder.addEventHandler("onCallBack",search_stop_location);
Start_geocoder.search(Start_myaddress);
}
/* Transformer l'adresse d'arrivée, donnée par l'utilisateur, en un point géocodé */
function search_stop_location(){
Stop_geocoder = new VMGeocoder();
Stop_myaddress = new VMAddress();
var elements_formulaire = document.forms['itisearch_form'].elements;
Stop_myaddress.address = elements_formulaire['form_Stop_address'].value;
Stop_myaddress.zipCode = elements_formulaire['form_Stop_CP'].value;
Stop_myaddress.city = elements_formulaire['form_Stop_city'].value;
Stop_myaddress.countryVMCode = elements_formulaire['form_Stop_country'].value;
Stop_geocoder.addEventHandler("onCallBack",search_step_location);
Stop_geocoder.search(Stop_myaddress);
}
/* Transformer l'étape, donnée par l'utilisateur, en un point géocodé */
function search_step_location(){
if (document.forms['itisearch_form'].elements['form_Step_address'].value != "" || document.forms['itisearch_form'].elements['form_Step_CP'].value != "" || document.forms['itisearch_form'].elements['form_Step_city'].value != ""){
Step_geocoder = new VMGeocoder();
Step_myaddress = new VMAddress();
var elements_formulaire =
document.forms['itisearch_form'].elements;
Step_myaddress.address = elements_formulaire['form_Step_address'].value;
Step_myaddress.zipCode = elements_formulaire['form_Step_CP'].value;
Step_myaddress.city = elements_formulaire['form_Step_city'].value;
Step_myaddress.countryVMCode = elements_formulaire['form_Step_country'].value;
Step_geocoder.addEventHandler("onCallBack",search_iti);
Step_geocoder.search(Step_myaddress);
} else {
search_iti();
}
}
/* Configurer la recherche d'itinéraire */
function search_iti(){
myiti = new VMItinerary();
myiti.addStopOver(Start_geocoder.result);
var elements_formulaire =
document.forms['itisearch_form'].elements;
if (elements_formulaire['form_Step_address'].value != ""
|| elements_formulaire['form_Step_CP'].value != ""
|| elements_formulaire['form_Step_city'].value != ""){
myiti.addStopOver(Step_geocoder.result);
}
myiti.addStopOver(Stop_geocoder.result);
myiti.setItineraryType(elements_formulaire['form_Type'].value);
myiti.setItineraryVehicleType(elements_formulaire['form_Vh'].value);
myiti.setCarType(elements_formulaire['form_Cat'].value);
myiti.setFuelType(elements_formulaire['form_Carb'].value);
myiti.setFuelCost(elements_formulaire['form_Prix'].value);
myiti.addEventHandler("onCallBack",iti_found);
myiti.search();
}
function iti_found(){
alert('Itineraire trouvé');
document.getElementById('result_action').style.display = '';
}
/* Affichage de l'itinéraire sous forme de texte */
function display_roadsheet(){
if (typeof(myiti)!="undefined"){
document.getElementById('youritidiv').innerHTML = myiti.roadSheet.getHTML(mymap);
document.getElementById('youritidiv').style.display = '';
} else {
alert('Aucun itinéraire chargé');
}
}
/* Affichage de l'itinéraire sur la carte */
function display_onmap(){
if (typeof(myiti)!="undefined"){
if (typeof(mymap)!="undefined"){
document.getElementById('yourmapdiv').innerHTML = "";
mymap = new VMMap(document.getElementById("yourmapdiv"));
mymap.addLayer(myiti.getItiAsVMComplexLayer("#FF0000",7,0.5));
mymap.drawMapFromLayers();
} else {
mymap = new VMMap(document.getElementById("yourmapdiv"));
mymap.addLayer(myiti.getItiAsVMComplexLayer("#FF0000",7,0.5));
mymap.drawMapFromLayers();
}
mymap.addLayer(myiti.roadSheet.getLayer());
mymap.showMapTools(3);
} else {
alert('Aucun itinéraire chargé');
}
}
/* Affichage de quelques informations concernant l'itinéraire */
function display_informations(){
strHTML =
"Distance totale en mètres :"
+myiti.getTotalDistance()+"m<br>"
+ "Distance parcourue sur autoroute : "
+myiti.getDistanceOnMotorway()+"m<br>"
+ "Temps total en secondes : "
+myiti.getTotalTime()+"s<br>"
+ "Temps de parcours sur autoroute : "
+myiti.getTimeOnMotorway()+"s<br>"
+ "Coût consommation carburant :"
+myiti.getTotalGasConsumption()+"€<br>"
+ "Coût péage autoroute : "
+myiti.getTollCost()+"€<br>"
+ "Coût vignette : "
+myiti.getRoadTaxCost()+"€<br>";
document.getElementById('youritiresumediv').style.display = '';
document.getElementById('youritiresumediv').innerHTML = strHTML;
}
/* L'affichage de la liste des pays */
function load_country(){
VMCountryUtil.addEventHandler(
"onCallBack",
function(){
document.getElementById("div_country_start").innerHTML =
VMCountryUtil.getSelectHTMLString("form_Start_country","FRA");
document.getElementById("div_country_stop").innerHTML =
VMCountryUtil.getSelectHTMLString("form_Stop_country","FRA");
document.getElementById("div_country_step").innerHTML =
VMCountryUtil.getSelectHTMLString("form_Step_country","FRA");
}
);
VMCountryUtil.loadCountryLabels();
}
</script>
</head>
<body onload="javascript:load_country();">
<form id="itisearch_form" runat="server">
<div>
<asp:Panel ID="pnl0" runat="server" Height="833px" Width="337px">
<asp:Label ID="lblCol" runat="server" Text="Collaborateur :"
Font-Underline="True"></asp:Label>
<br />
<br />
<asp:Label ID="lblNomCol" runat="server" Text="Nom :"></asp:Label>
<br />
<asp:TextBox ID="txbNomCol" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblPrenomCol" runat="server" Text="Prénom :"></asp:Label>
<br />
<asp:TextBox ID="txbPrenomCol" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblRueCol" runat="server" Text="Rue :" AssociatedControlID="form_Start_address"></asp:Label>
<br />
<asp:TextBox ID="form_Start_address" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblCpCol" runat="server" Text="Code Postal : " AssociatedControlID="form_Start_CP"></asp:Label>
<br />
<asp:TextBox ID="form_Start_CP" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblVilleCol" runat="server" Text="Ville : " AssociatedControlID="form_Start_city"></asp:Label>
<br />
<asp:TextBox ID="form_Start_city" runat="server"></asp:TextBox>
<br />
<asp:Label ID="form_Start_country" runat="server" Text="Pays : "></asp:Label>
<div id="div_country_start"></div>
<br />
<br />
<br />
<asp:Label ID="lblCli" runat="server" Font-Underline="True" Text="Client : "></asp:Label>
<br />
<br />
<asp:Label ID="lblNomCli" runat="server" Text="Nom :"></asp:Label>
<br />
<asp:TextBox ID="txbNomCli" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblPrenomCli" runat="server" Text="Prénom :"></asp:Label>
<br />
<asp:TextBox ID="txbPrenomCli" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblRueCli" runat="server" Text="Rue :" AssociatedControlID="form_Stop_address"></asp:Label>
<br />
<asp:TextBox ID="form_Stop_address" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblCpCli" runat="server" Text="Code Postal : " AssociatedControlID="form_Stop_CP"></asp:Label>
<br />
<asp:TextBox ID="form_Stop_CP" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblVilleCli" runat="server" Text="Ville : " AssociatedControlID="form_Stop_city"></asp:Label>
<br />
<asp:TextBox ID="form_Stop_city" runat="server"></asp:TextBox>
<br />
<asp:Label ID="form_Stop_country" runat="server" Text="Pays : "></asp:Label>
<div id="div_country_stop"></div>
</asp:Panel>
</div>
<asp:Panel ID="pnl1" runat="server"
style="position: relative; top: -830px; left: 341px; width: 398px; height: 826px">
<asp:Label ID="lblEtape" runat="server" Text="Etape : " Font-Underline="True"></asp:Label>
<br />
<asp:Label ID="lblRueEtape" runat="server" Text="Rue : " AssociatedControlID="form_Step_address"></asp:Label>
<br />
<asp:TextBox ID="form_Step_address" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblCpEtape" runat="server" Text="Code Postal : " AssociatedControlID="form_Step_CP"></asp:Label>
<br />
<asp:TextBox ID="form_Step_CP" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblVilleEtape" runat="server" Text="Ville : " AssociatedControlID="form_Step_city"></asp:Label>
<br />
<asp:TextBox ID="form_Step_city" runat="server"></asp:TextBox>
<br />
<asp:Label ID="form_Step_country" runat="server" Text="Pays : "></asp:Label>
<div id="div_country_step"></div>
<br />
<br />
<asp:Label ID="lblType" runat="server" Text="Type de trajet : "></asp:Label>
<br />
<select id="form_Type" name="D1" style="width: auto; height: auto">
<option value="0">Recommendé par Michelin</option>
<option value="1">Le plus court</option>
<option value="2">Le plus rapide</option>
<option value="3">Economique</option>
<option value="4">Découverte</option>
<option value="5">A pieds</option>
<option value="6">A vélo</option>
</select>
<div id="option_type">
<asp:Label ID="lblTypeVeh" runat="server" Text="Type de véhicule : "></asp:Label>
<br />
<select id="form_Vh">
<option value="0">Automobile</option>
<option value="1">Moto</option>
<option value="2">Caravane</option>
</select>
<br />
<asp:Label ID="lblCatveh" runat="server" Text="Catégorie de véhicule : "></asp:Label>
<br />
<select id="form_Cat">
<option value="0">Citadine</option>
<option value="1">Compacte</option>
<option value="2">Familiale</option>
<option value="3">Routière</option>
<option value="4">Luxe</option>
</select>
<br />
<asp:Label ID="lblTypeCarb" runat="server" Text="Type de carburant : "></asp:Label>
<br />
<select id="form_Carb">
<option value="0">Essence</option>
<option value="1">Diesel</option>
<option value="2">GPL</option>
</select>
<br />
<asp:Label ID="lblCoutCar" runat="server" Text="Coût du carburant (en euro) : " AssociatedControlID="form_Prix"></asp:Label>
<br />
<asp:TextBox ID="form_Prix" runat="server"></asp:TextBox>
</div>
<br />
<br />
<asp:Button ID="btnRechercher" runat="server"
onclientclick="search_start_location();" Text="Rechercher"/>
</asp:Panel>
<asp:Panel ID="pnl2" runat="server" Width="398px"
style="position: relative; top: -1654px; left: 743px; height: 823px; margin-right: 0px">
<div id="result_action">
<asp:Button id="btnCarte" runat="server" Text="Afficher la carte de l'itinéraire" OnClientClick="display_onmap()" />
<br />
<asp:Button id="btnDetail" runat="server" Text="Afficher l'itinéraire détaillé" OnClientClick="display_roadsheet()" />
<br />
<asp:Button id="btnResume" runat="server" Text="Afficher l'itinéraire résumé" OnClientClick="display_informations()" />
</div>
<div id="yourmapdiv"></div>
<div id="youritiresumediv"></div>
<div id="youritidiv"></div>
</asp:Panel>
</form>
</body>
</html>
Ma question est : pensez vous que mon problème vient de mon code ou alors est-ce à cause de la clé d'activation.
Merci d'avance pour vos réponse qui je l'espère me feront avancer.
Afficher la suite