How to add a map with leaflet programmatically

Sometimes you would like to add a map to a node or block without the need for detailled configuration options. You simply want to display a map and be done with it.
Fortunately this is an easy task using Leaflet(link is external).

Say you have a value for the location and one for the country and would like to print this "address" in a map.
So you need to first install Leaflet(link is external) and Geocoder(link is external) and then use this function(link is external) to generate the map:

Easy, isn't it?

 

Stefan Borchert
  • CEO

Stefan maintains several Drupal contributed modules, has been working on Drupal core since the early days, and is author of Drupal 8 Configuration Management (Packt Publishing).