Reinos.nl internet media examples

JS API Interactive search

Maps 5.0.1 Live

A search field above the map: the Javascript API geocodes what the visitor types, removes the old marker and adds a new one.

Template
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>

<form style="margin-bottom: 10px;">
<input name="address" style="border: 1px solid green;"/>
<input type="submit">
</form>


{exp:reinos_maps:html_header}
{exp:reinos_maps:map
  center:address="heerde"
  width="100%"
}
{exp:reinos_maps:html_footer}

<script>
$(function(){
  $("form").submit(function(){
    //geocode address
    REINOS_MAPS.api("geocode", {
      address : $('input[name="address"]').val(),
      callback : function(result, type){

        //nothing found
        if (!result.success || result.objects.length === 0) {
          return;
        }

        //remove old markers
        REINOS_MAPS.api("removeMarkers", {
          mapID : "reinos_map_1"
        });

        //add marker
        REINOS_MAPS.api("addMarker", {
          mapID : "reinos_map_1",
          lat: result.objects[0].latitude,
          lng: result.objects[0].longitude,
          title: result.objects[0].city
        });

        //Fit the map
        REINOS_MAPS.api("fitMap", {
          mapID : "reinos_map_1"
        });
        REINOS_MAPS.api("setZoom", {
          mapID : "reinos_map_1" ,
          zoom : 6
        });
      }
    });
    return false;
  });
});

</script>

Build it in your own site

What this example needs in ExpressionEngine, step by step.

  1. Install Maps.
  2. Put the code in a template.

This example comes from the Maps docs: the preview runs exactly the code above.