VIAMICHELIN JAVASCRIPT API


Examples

Introduction

The Poi component allows you to find out the closest static POIs from a specific location (GPS center - WGS84 coordinates) and returns a list of point of interest, such as Michelin POIs Hotels, Restaurants and Michelin travel. You can also display Poi from your own data base (points of interest) hosted by MICHELIN.     

The component in charge of this service is named: "ViaMichelin.Api.Poi".

To get start easily, please check the sample on the Quick start section.

The main uses of POI searches

 1.    Search for closest POIs 

This sample is going to show you how to make a proximity search around a gps position of your choice (ex: your home GPS coordinates) 

The FIND_POI service is used to make a proximity search.

For more detail about this sample, please have a look at our Quick start guide.

  
var conf = {
  db : "163978",
  service : ViaMichelin.Api.Constants.Poi.SERVICE_TYPE.FIND_POI,
  center : {
    // Paris
    lon : 2.35107,
    lat : 48.85684
  }
};
var output = $_id("output");
var callbacks = {
  onSuccess : function (results) {
    var outputHTML, i, item, poi;
    outputHTML = results.poiList.length + " résultats trouvés.";
    for (i = 0; i < results.poiList.length; i++) {
      item = results.poiList[i];
      poi = item.poi;
      outputHTML += "\n- " + poi.name + " (à " + item.dist + "m)";
    }
    output.innerHTML = outputHTML;
  }
};
VMLaunch("ViaMichelin.Api.Poi", conf, callbacks);


  

Demo

 

2.    Find POIs by name 

With find Poi, it is possible to find out list of POI selected by its names or part of its names.

In this example, we want to find all POIs where the POI's name contains the word 'Louvre'.

Then, FIND_POI can’t be used, because it needs coordinates center. So, we are going to use FIND_POI_BY_CRITERIA

  

var conf = {
  db : "163978",
  service : ViaMichelin.Api.Constants.Poi.SERVICE_TYPE.FIND_POI_BY_CRITERIA,
  name : "Louvre"
};
var output = $_id("output");
var callbacks = {
  onSuccess : function (results) {
    var outputHTML, i, item, poi;
    outputHTML = results.poiList.length + " résultats trouvés.";
    for (i = 0; i < results.poiList.length; i++) {
      item = results.poiList[i];
      poi = item.poi;
      outputHTML += "\n- " + poi.name.replace(/(louvre)/gi, '$1');
    }
    output.innerHTML = outputHTML;
  }
};
VMLaunch("ViaMichelin.Api.Poi", conf, callbacks);


  

Demo

 

3.    Search for POIs from a provided list 

In this section, we are going to show you how to use input POI list instead of database.

The service to use for this kind of research is called FIND_INPUT_POI.

To provide the list of POIs to the component we use inputpoi property.

We are going to fix the radius at 25 000m, using the property dist.

The 4 POIs showed in this example will be transmitted to the service FIND_INPUT_POI, which classify it according to the distance and exclude the most far away. 

  
var pois = [
  {
    name : "Resto basque",
    coords : {lon : 2.36, lat : 48.6}
  },
  {
    name : "Resto savoyard",
    coords : {lon : 2.33, lat : 48.8}
  },
  {
    name : "Resto breton",
    coords : {lon : 2.37, lat : 48.67}
  },
  {
    name : "Resto réunionais",
    coords : {lon : 2.39, lat : 48.83}
  }
];
var conf = {
  service : ViaMichelin.Api.Constants.Poi.SERVICE_TYPE.FIND_INPUT_POI,
  inputpoi : pois,
  center : {
    lon : 2.35107,
    lat : 48.85684
  },
  dist : 25000
};
var output = $_id("output");
var callbacks = {
  onSuccess : function (results) {
    var outputHTML, i, item, poi;
    outputHTML = results.poiList.length + " résultats trouvés.";
    for (i = 0; i < results.poiList.length; i++) {
      item = results.poiList[i];
      poi = item.poi;
      outputHTML += "\n- " + poi.id + " (à " + item.dist + "m)";
    }
    output.innerHTML = outputHTML;
  }
};
VMLaunch("ViaMichelin.Api.Poi", conf, callbacks);

  

Demo