Adding a Leaflet map based on php in Wordpress



I use a php-script within a plugin on a Wordpress-site to geocode an user-supplied address. After this I would like to visualize the point on a leaflet map. In order to do so I wanted to use the built-in functions from the leaflet-map plugin. I tracked down the class for this in the Leaflet_Map_Shortcode. This class provideds the function shortcode. This is also added to the shortcode in Wordpress (Lines 135 onwards):

'leaflet-map' => array(
'file' => '',
'class' => 'Leaflet_Map_Shortcode');
foreach ($this->_shortcodes as $shortcode => $details) {
include_once $shortcode_dir . $details['file'];
add_shortcode($shortcode, array($details['class'], 'shortcode'));

My Intention was using this in a straightforward way:

... some code for geocoding...
$coords = array("lng" => 11, "lat" =>43 );

$myMap= new Leaflet_Map_Shortcode;

But nothing happens (i.e. nothing is displayed). So this leads me to several questions:

  • Why does this not work?
  • What's the best way of debugging this code?
  • Is there a better solution to my problem?

Continue reading...