Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogleMap and Wordpress: problems in creating markers dynamically
    text
    copied!<p>I would like to create markers dinamycally on a GoogleMap in Wordpress. The markers are computed from the post tags (which are all locations). I have no problem in computing coordinates, and creating a php array. The problem comes when I have to plot the dynamically generated data stored in the array on the map, because no pointers are displayed</p> <p>I specified the following instructions in WP header.php:</p> <pre><code> &lt;script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=mykey" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;?php bloginfo('template_directory'); ?&gt;/mapLocations_cache.php" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="&lt;?php bloginfo('template_directory'); ?&gt;/map_functions.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>The dynamically created array (that I save in mapLocations_cache.php) has the following format:</p> <pre><code> var markers = [ { 'latitude': 62.3908358, 'longitude': 17.3069157, 'title': 'it happens in Sundsvall', 'news': 'che noia5' }, ]; </code></pre> <p>The map_functions.js contains the following code:</p> <pre><code> var centerLatitude = 62.3908358; var centerLongitude = 17.3069157; var startZoom = 4; var map; function addMarker(latitude, longitude, description) { var marker = new GMarker(new GLatLng(latitude, longitude)); GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(description); } ); map.addOverlay(marker); } function init() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom); for(id in markers) { addMarker(markers[id].latitude, markers[id].longitude, markers[id].title); } } } window.onload = init; window.onunload = GUnload; </code></pre> <p>Since when I use a file/array that is NOT dynamically generated, this code works well, my suspicion is that the JavaScript included in the header is not completed appropriate when I try to harvest data dynamically from WordPress posts and tags.</p> <p>Any suggestion would help :-(</p> <p>Cheers</p> <p>Marina</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload