WordPress.org

Ready to get started?Download WordPress

Forums

WP Flexible Map
[resolved] Dynamically generated KML (3 posts)

  1. ei3hmb
    Member
    Posted 1 year ago #

    Hi there,

    I wrote a short php script to generate kml data dynamically from MySQL.
    There is no problem to display map with markers, but what I can see on the map is not what I have generated form my php script. It looks like google maps caches data loaded from the very first kml output.

    The code is:
    [flexiblemap src="http://EI3HMB.e-donegal.eu/map.php" width="720" height="600"]

    How to force google maps to display kml generated in real time, not form cache?

    J.

    http://wordpress.org/extend/plugins/wp-flexible-map/

  2. webaware
    Member
    Plugin Author

    Posted 1 year ago #

    G'day J,

    This one's in the FAQ:

    Why won't my KML map update when I edit the KML file?

    Google Maps API caches the KML file, so it often won't get your new changes. To force a change, append a URL query parameter with a number (known as a cache buster) and increment the number each time you change the KML file. A nice simple and commonly used parameter name is v (for version), like this: http://example.com/my-map.kml?v=2

    So, add a query parameter to the source URL. I suggest using the output of the time() function, which will change every second. If you aren't generating the shortcode dynamically, then you can use a filter hook to change the KML src:

    add_filter('flexmap_shortcode_attrs', 'my_dynamic_kml');
    
    function my_dynamic_kml($attrs) {
        // src attribute is specified and is a PHP file?
        if (isset($attrs['src']) && strpos($attrs['src'], '.php') !== false) {
            // append a cache buster
            $attrs['src'] = add_query_arg(array('v' => time()), $attrs['src']);
        }
    
        return $attrs;
    }

    cheers,
    Ross

  3. ei3hmb
    Member
    Posted 1 year ago #

    Ross,

    OK, it works now().

    Many thanks,

    Jacek

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags