Home Forums Front-end Issues infowindow help on google map


infowindow help on google map

  • Hi, I am using Advanced Custom Fields to set the location of a post and display it on a map within my custom post template and it works great. But I have also created a google map that plots all the locations of my custom posts types on one map.

    My problem is that I can’t get it to pull content or a link into the infowindow. I’ve looked around the internet and tried to use the code that google suggests as well as the users on this site, but I seem to be doing something wrong. All it does is display the title followed by a weird symbol. Any help would be appreciated 🙂

    This is the code I am using:

      $args = array(
    	  'post_type'		=> 'offices',
    	  'posts_per_page'	=> -1
    // query
    $wp_query = new WP_Query( $args );
    $NUM = 0;
      <div id="map"></div>
    <script src='' type='text/javascript'></script>
    <script type="text/javascript">
        var locations = [<?php while( $wp_query->have_posts() ){
        $location = get_field('location'); // IMPORTANT << Change this for your Google map field name !!!!!!
    ['<?php the_title(); ?>',   <?php echo $location['lat']; ?>, <?php echo $location['lng'];?>, <?php $NUM++ ?> ],
       <?php } ?> ];
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 7, /*Here you change zoom for your map*/
          center: new google.maps.LatLng(42.6, -76.0), /*Here you change center map first location*/
           mapTypeId: google.maps.MapTypeId.ROADMAP
        var infowindow = new google.maps.InfoWindow();
        var marker, i;
        for (i = 0; i < locations.length; i++) {
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
          google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
    , marker);
          })(marker, i));
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.