• Hello,

    I’ve been trying to do this all day: I want to load a map, create multiple polygons and when the user clicks a polygon an infoWindow should appear with content from a blogpost corresponding to the clicked polygon.

    Everything is working except I can’t get my head around loading a specific post from JavaScript. Can I somehow load the content into the infowindow using AJAX?

    This is my code to show the infoWindow:

    function showMyWindow(event){
        	var contentString = "Somehow load the content();";
    
        	// Replace our Info Window's content and position
        	  infowindow.setContent(contentString);
        	  infowindow.setPosition(event.latLng);
    
        	  infowindow.open(map);
        }

    I’m using the latest Google Maps API.

    Any help is much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    Have you managed to work this out? I’m interested in something very similar.

    Thanks.

    Thread Starter vfreriks

    (@vfreriks)

    Hello,

    I managed to do this. Here’s the function I ended up using, but the site never went into production. It needs tweaking I guess.
    Good luck!

    function showMyWindow(event){
        	var contentString = "<?php query_posts('p=469'); the_post(); ?><h2><?php the_title(); ?></h2><p><?php the_content(); ?></p>";
    
        	// Replace our Info Window's content and position
        	  infowindow.setContent(contentString);
        	  infowindow.setPosition(event.latLng);
    
        	  infowindow.open(map);
        }

    Thanks!

    I’ll give it a go.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Load WordPress post into Google Maps infoWindow’ is closed to new replies.