Adding a Leaflet map based on php in Wordpress

S

Seb

Guest
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 class.map-shortcode.php-file: 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.map-shortcode.php',
'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:

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

$myMap= new Leaflet_Map_Shortcode;
$myMap->shortcode($coords);
?>


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...
 
Top