Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open Infowindow On Click Google Maps

    How can I get the marker infowindow to open on click instead of by default when the page loads?

    www.driftcoffeehouse.com

    Code:
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false"></script>
    							<script type="text/javascript">
    							  //<![CDATA[
    							  var map;
    							  var geocoder;
    
    							  initialize();
    
    							  function initialize() {
    								 geocoder = new google.maps.Geocoder();
    								 geocoder.geocode({
    									'address': '<?php echo esc_js(get_option('mycuisine_address')); ?>',
    									'partialmatch': true}, geocodeResult);
    							  }
    
    							  function geocodeResult(results, status) {
    
    								 if (status == 'OK' && results.length > 0) {
    									var latlng = new google.maps.LatLng(results[0].geometry.location.b,results[0].geometry.location.c);
    									var myOptions = {
    									   zoom: 13,
    									   center: results[0].geometry.location,
    									   mapTypeId: google.maps.MapTypeId.ROADMAP
    									};
    
    									map = new google.maps.Map(document.getElementById("gmaps-container"), myOptions);
    									   var marker = new google.maps.Marker({
    									   position: results[0].geometry.location,
    									   map: map
    									});
    
    									var contentString = '<div id="et-gmaps-content">'+
    									'<div id="bodyContent">'+
    									
    '<p><a target="_blank" href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q='+escape(results[0].formatted_address)+'&amp;ie=UTF8&amp;view=map">'+results[0].formatted_address+'</a>'+
    									'</p>'+
    									'</div>'+
    									'</div>';
    
    									
    
    									google.maps.event.addListener(marker, 'click', function() {
    									   infowindow.open(map,marker);
    									});
    
    var infowindow = new google.maps.InfoWindow({
    content: contentString,
    maxWidth: 100
    });
    
    									google.maps.event.trigger(marker, "click");
    
    								 } else {
    									//alert("Geocode was not successful for the following reason: " + status);
    								 }
    							  }
    							  //]]>
    							</script>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 612 Times in 611 Posts
    In the code you provided you have this
    Code:
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false"></script>
    <script type="text/javascript">
    //<![CDATA[
    var map;
    var geocoder;
    
    initialize();
    That runs your code automatically. Comment it out and have a button start the code.

    Code:
    <button onclick="initialize();">Show Map</button> 
    
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false"></script>
    <script type="text/javascript">
    //<![CDATA[
    var map;
    var geocoder;
    
    //initialize();
    Last edited by sunfighter; 01-28-2014 at 04:51 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •