infowindow on googlemap for wordpress
-
I m trying to create a googlemap integrating informations from wordpress posts, I succeed to call the various markers from the category I want,
but I need each marker when click to open a infowindow with the title of the post and a link to the post itself, but after trying different possibilities I can’t figure out how to make this work … If someone can help me on this ? Here is the code I have so far :<div id="map" style="width: 100%; height: 300px;"></div> <script> function initialize() { var locations = [ <?php $query = new WP_Query( 'cat=3' ); ?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> [<?php echo get_post_meta( $post->ID, 'location', true ); ?>, "<?php the_title(); ?>"], <?php endwhile; wp_reset_postdata(); ?> <?php endif; ?> ]; var map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: new google.maps.LatLng(45.835163, 9.029694), mapTypeId: google.maps.MapTypeId.ROADMAP, styles : [{featureType:'all',stylers:[{saturation:-100},{gamma:0.0}]}] }); 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][0], locations[i][1]), map: map, <?php if(in_category('8')):?> icon: 'https://maps.google.com/mapfiles/kml/shapes/schools_maps.png', <?php elseif (in_category('9')):?> icon: 'https://maps.google.com/mapfiles/kml/shapes/library_maps.png', <?php endif;?> }); } } google.maps.event.addDomListener(window, 'load', initialize); </script>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘infowindow on googlemap for wordpress’ is closed to new replies.