Advanced KML Overlay

I have posts which are U.S. Counties.

Using the Google Maps and my custom Lat/Long fields, I can show auto-associate a map to each post. Cool!

However, Google seems to have County boundaries in KML, discussed here:

I would LOVE to be able to assign kml as a custom field(?) or similar to each of my posts and have the appropriate KML overlay the map, which is centered at the lat/long of the county centroid.

I am open to ideas, suggestions, etc. Thanks!

  • Kimberly
    • Champion of Loops

    Wow sounds like quite a project!


    I don't have the experience with Google maps to say if this is possible. Perhaps some of our more seasoned google maps user can comment on this one.

    I'll also ask the developer to comment if he has the chance :slight_smile:

  • kenlyle
    • Site Builder, Child of Zeus

    Thanks, Kimberly.

    This plugin seems SOOOOOOO close...but I have the idea so far that the tags have to be created manually. I could batch update my posts with some [lat/long, KML= ] type tag, but it seems like they also need a map number, and I am not sure where that is stored or from....and I have 3000 of these, so doing them by hand is not an option.

    It seems that I can't readily combine what I have done, just using Custom Fields, with the KML option, but I hope that I am overlooking something simple...

  • Vladislav
    • Dead Eye Dev


    Indeed, doing 3k+ posts by hand isn't really an option at all. However, you can use the automatic approach and just auto-load the Fusion Table data from the article you mentioned above with a bit of javascript. For an example, this piece of code will auto-overlay the "State KML" Fusion Table over your existing maps:

    (function ($) {
    $(document).bind("agm_google_maps-user-map_initialized", function (e, map) {
    	var layer_id = '17aT9Ud-YnGiXdXEJUyycH2ocUqreOeKGbzCkUw',
    		layer = new google.maps.FusionTablesLayer(layer_id, {
    		suppressInfoWindows: true
  • kenlyle
    • Site Builder, Child of Zeus

    Ok, THANKS!

    Can you tell me precisely where this should go? Anywhere in the main plugin file, I guess?

    Would it perform better to somehow just load the one single county boundary file from the 5th column of the US Counties table, somehow?

  • Vladislav
    • Dead Eye Dev


    The main plugin javascript file (js/google_maps_user.js) could be a possible place - if you want to put the code there, put it at the very end, after everything else. However, your changes will be trumped over with the next plugin release, when you update the plugin.

    I have successfully used my theme's footer.php for testing this very snippet, just before the </body> tag (of course, you'll want to wrap your code in <script></script> for this). If your theme supports custom footer HTML snippets in theme settings, that's probably the best place, as it'll get preserved across updates.

  • kenlyle
    • Site Builder, Child of Zeus

    Here's what worked for us:


    // Load KML overlay
    $(document).bind("agm_google_maps-user-map_initialized", function(e, map, data) {
    var tableId = '0IMZAFCwR-t7jZnVzaW9udGFibGVzOjIxMDIxNw';
    // The column in your table containing the LOCATIONs.
    var locationColumn = 'geometry';
    //Where Condition
    var where_qry = "GEO_ID = '<?php echo $geo_id ?>'";

    var kml = new google.maps.FusionTablesLayer({
    query: {
    select: locationColumn,
    from: tableId,
    where: where_qry
    map: map


    Something about using the encrypted version of the FusionTable name(?) according to my team...

    Earlier, we had defined $geo_id = '05000US'.$fips_value; where we had retrieved the $fips_value from postmeta.

    Thanks to Vladislav for pointing us in the right direction.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.