Autocomplete input

  
  

Autocomplete input

Search box, compatible with addresses (ex: Justitiestraat 34, Antwerpen) and coordinates (Ex: 51.2088407, 4.4054899)

<!DOCTYPE html>
<html>
  <head>
    <title>Autocomplete input</title>
    <script src="https://maps.cercalia.com/maps/loader.js?key=YOUR_API_KEY&v=5&lang=en&theme=1976d2"></script>
  </head>
  <body>

    <cercalia-autocomplete id="autocomplete"></cercalia-autocomplete>
    <pre>
      <code id="code">
      </code>
    </pre>
    <script>
      var map;
      document.addEventListener('cercalia-ready', function() {
        var reverseGeocoding = new cercalia.service.ReverseGeocoding();
        var autocomplete = new cercalia.service.Autocomplete({
          autocompleteId: 'autocomplete',
          callbackFunction: function (data) {
            if (data instanceof cercalia.LonLat) {
              reverseGeocoding.getDirection(data, function(rgResponse) {
                showResponseCode(rgResponse);
              });
            } else {
              showResponseCode(data);
            }
          }
        });
      });

      function showResponseCode(data) {
        var responseDiv = document.querySelector('#code');
        responseDiv.innerHTML = JSON.stringify(data, null, 4);
      }
    </script>
  </body>
</html>