WordPress.org

Ready to get started?Download WordPress

Forums

Load WordPress post into Google Maps infoWindow (4 posts)

  1. vfreriks
    Member
    Posted 3 years ago #

    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!

  2. elba00
    Member
    Posted 2 years ago #

    Hi there,

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

    Thanks.

  3. vfreriks
    Member
    Posted 2 years ago #

    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);
        }
  4. elba00
    Member
    Posted 2 years ago #

    Thanks!

    I'll give it a go.

Topic Closed

This topic has been closed to new replies.

About this Topic