VIAMICHELIN JAVASCRIPT API


Quickstart

Loading of the APIJS

To load the APIJS ViaMichelin , use the script tag on the following example, on the head tag of your HTML code, with your Key number and the language (LANG).

 

<script src="http://apijsv2.viamichelin.com/apijsv2/api/js?key=KEY&lang=LANG" type="text/javascript"> </script>

For more details about KEY and LANG, refer to the loading of APIJS.                     

Use of the itinerary component

The example shows the display of the main informations of itinerary component.

The HTML

Then, we create a tag called « pre » in order to display the informations received by the component.

 

<pre id="output"></pre>

 

Configuration of the component

To calculate a route, it is necessary to provide the starting point and the arrival. That is made with the property steps on the configuration.

var paris = {

  coords : {

    lon : 2.35107,

    lat : 48.85684

  }

};

var bordeaux = {

  coords : {

    lon : -0.57574,

    lat : 44.83498

  }

};

var conf = {

  steps : [

    paris,

    bordeaux

  ]

};

 

Result of the calculation

Once calculation carried out, the component returns the result via the event onSuccess. The result contains a property header with the main  informations of the result.

 

var output = $_id("output");

var callbacks = {

  onSuccess : function (result) {

    iti = result.header.summaries[0];

    var t = iti.totalTime,

      h = Math.floor(t / 3600),

      m = Math.floor(t % 3600 / 60),

      report = "";

    report +=   "Distance : " + iti.totalDist / 1000 + "km";

    report += "\nDurée    : " + h + "h " + m + "min";

    report += "\nCoût     : " + iti.tollCost.car / 100 + "€";

    output.innerHTML = report;

  }

};

 

Launch of the calculation

The itinerary component is called ViaMichelin.Api.Itinerary. It must be used with the VMLaunch() method, with 2 parameters : conf and callbacks.

 

VMLaunch("ViaMichelin.Api.Itinerary", conf, callbacks);

 

Demonstration

To see the result, check the page demonstration.

Go further with the functionality

View other examples of the use of the component.

 

Consult the references of the component.