<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>google maps Archives - Michael Soriano</title>
	<atom:link href="https://michaelsoriano.com/tag/google-maps/feed/" rel="self" type="application/rss+xml" />
	<link>https://michaelsoriano.com/tag/google-maps/</link>
	<description>I turn code into captivating user experiences for the web</description>
	<lastBuildDate>Sat, 16 Jul 2022 18:24:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.4</generator>
	<item>
		<title>How to fully customize your Google Map Info Windows with Infobox</title>
		<link>https://michaelsoriano.com/customize-google-map-info-windows-infobox/</link>
					<comments>https://michaelsoriano.com/customize-google-map-info-windows-infobox/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Fri, 04 Mar 2016 04:43:51 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[Handlebars]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=5499</guid>

					<description><![CDATA[<p>So I had a recent task of designing an infowindow for a Google map. Just in case you do not know, Google maps API has the ability of overlaying some HTML on top of a marker, also known as an &#8220;infowindow&#8220;. The problem is, the default infowindow has limited options for HTML styling. View Demo [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/customize-google-map-info-windows-infobox/">How to fully customize your Google Map Info Windows with Infobox</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>So I had a recent task of designing an infowindow for a Google map. Just in case you do not know, Google maps API has the ability of overlaying some HTML on top of a marker, also known as an &#8220;<a href="https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple">infowindow</a>&#8220;. </p>



<p>The problem is, the default infowindow has limited options for HTML styling.</p>



<p class="btn"><a href="http://demo.michaelsoriano.com/infobox/">View Demo</a></p>



<p>The default infowindow looks like below:</p>



<p><img fetchpriority="high" decoding="async" width="354" height="261" class="alignnone size-full wp-image-5511" src="https://michaelsoriano.com/wp-content/uploads/2016/03/regular.png" alt="regular" srcset="https://michaelsoriano.com/wp-content/uploads/2016/03/regular.png 354w, https://michaelsoriano.com/wp-content/uploads/2016/03/regular-300x221.png 300w" sizes="(max-width: 354px) 100vw, 354px" /></p>



<p>You can only style the inside of the window. We need a bit more flexibility and style the entire window. </p>



<p>Thankfully there&#8217;s this plugin called &#8220;<a href="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/examples.html">Infobox</a>&#8220;. With InfoBox, you can style the entire window by simply passing a few parameters. In my case, I need to make the window look like below:</p>



<p><img decoding="async" width="354" height="261" class="alignnone size-full wp-image-5519" src="https://michaelsoriano.com/wp-content/uploads/2016/03/modified2.jpg" alt="modified2" srcset="https://michaelsoriano.com/wp-content/uploads/2016/03/modified2.jpg 354w, https://michaelsoriano.com/wp-content/uploads/2016/03/modified2-300x221.jpg 300w" sizes="(max-width: 354px) 100vw, 354px" /></p>



<p>Ready to get started? Let&#8217;s start by adding our script to InfoBox. Note that if you&#8217;re loading Google Maps asynchronously, you need to add your script in your callback method.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var initMap = function() {
  var s = document.createElement("script");
  s.type = "text/javascript";
  s.src = "js/infobox.js";
  $("head").append(s);
  var map = new google.maps.Map(document.getElementById('map-wrap'), {
    center: {lat: 33.78444500, lng: -118.15378000},
    zoom: 8
  });
}</code></pre>



<p>Once your scripts are loaded, you should see your map, and add a simple marker like so:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var marker, i;
marker = new google.maps.Marker({
   position: new google.maps.LatLng(22.556444, -44.565),
   map: map
})</code></pre>



<p>Now, InfoBox has plenty of options &#8211; so I just leave the defaults alone. What we really need is the &#8220;boxStyle&#8221; object. This we can pass our CSS as key/value pairs. This is the style of the outermost box &#8211; the box that the default infowindow doesn&#8217;t let you customize easily.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var ibOptions = {
    		disableAutoPan: false
    		,maxWidth: 0
    		,pixelOffset: new google.maps.Size(-140, 0)
    		,zIndex: null
    		,boxStyle: {
          padding: "0px 0px 0px 0px",
          width: "252px",
          height: "40px"
        },
        closeBoxURL : "",
        infoBoxClearance: new google.maps.Size(1, 1),
    		isHidden: false,
    		pane: "floatPane",
    		enableEventPropagation: false
    	};</code></pre>



<p>Once that&#8217;s done, let&#8217;s create a click handler, so our InfoBox will pop out when our marker is clicked. The code below is an example of a closure. We&#8217;re only including the &#8220;non static&#8221; properties inside our closure, so you&#8217;ll notice that our &#8220;<em>innerHTML</em>&#8221; property is inside.</p>



<pre class="wp-block-code"><code class="">google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
        var source   = $("#infobox-template").html();
        var template = Handlebars.compile(source);
        var boxText = document.createElement("div");
        boxText.style.cssText = "margin-top: 8px; background: #fff; padding: 0px;";
        boxText.innerHTML = template(subSet[i]);
        ibOptions.content = boxText
        var ib = new InfoBox(ibOptions);
      	ib.open(map, marker);
        map.panTo(ib.getPosition());
      }
  })</code></pre>



<p>I am also using <a href="http://handlebarsjs.com/">Handlebars</a> for templating, so the template is compiled multiple times. Also inside click handler above, and only shows up when the marker is actually clicked. My template will look like below. Remember that I have multiple of these boxes.</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;div class="info-box-wrap">
  &lt;img src="{{img_src}}" />
  &lt;div class="info-box-text-wrap">
  &lt;h6 class="address">{{address}}, {{city}} {{zip}} {{state}}&lt;/h6>
  &lt;p class="price">{{price}}&lt;/p>
&lt;/div>
&lt;div class="action-btns">&lt;/div>
&lt;/div></code></pre>



<p>Finally, the styles. Remember, InfoBox has already done the outer shell styles. Now it&#8217;s up to us to style the inner part of our box. So simply hack away with your CSS chops:</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.info-box-wrap {
  background:#fff;
  overflow: hidden;
  box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.08);
}
.info-box-text-wrap {
  height:40px !important;
  width:120px;
  float:left;
  overflow: hidden;
}
.action-btns {
  float:left;
  width:70px;
  overflow: hidden;
  position: relative;
  top:12px;
  left: 6px;
}
.action-btns i {
  font-size: 18px;
  color: #78A737;
  margin-left: 3px;
}
.action-btns i:hover {
  transition: color 0.5s ease;
  color:#ccc;
  cursor: pointer;
}
.action-btns i.fa-heart-o {
  font-weight: bold;
}
.info-box-text-wrap h6.address {
  padding:6px 5px 1px 0;
  margin:0 0 0 0;
  font-family:"Roboto Slab";
  color: #0c99c8;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-box-text-wrap p {
  padding:0 0 0 0;
  margin:0 0 0 0;
}
.info-box-text-wrap p.price {
  color:#B25B00;
}
.info-box-wrap  img {
  width:40px !important;
  height:40px;
  float:left;
  margin-right: 10px;
  padding-top:0;
  margin-top:0;
}</code></pre>



<p>With the above code everything should be in place. All we need is an arrow that points back from our box to our marker.</p>



<h3 class="wp-block-heading">Creating the Arrow</h3>



<p>There is an awesome article on how to create <a href="https://css-tricks.com/snippets/css/css-triangle/">traingles</a> that is pure CSS. We really don&#8217;t need an image for this type of thing. Another thing, we&#8217;re going to use the <strong>::before</strong> pseudo selector to insert our triangle. This prevents us from adding unnecessary DIVs into our markup.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.infoBox:before{
  content : " ";
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid #fff;
  position:absolute;
  top:-10px;
  left:130px;
}</code></pre>



<p>Note the &#8220;content&#8221; property with the value of &#8221; &#8220;. This makes it so the ::before selector is actually visible in the DOM.</p>



<p>And the final result looks like below. Note that the map automatically centers to the marker that is clicked. That is in our click handler &#8220;<em>map.panTo(ib.getPosition())</em>&#8221; method.</p>



<p><img decoding="async" width="489" height="293" class="alignnone size-full wp-image-5520" src="https://michaelsoriano.com/wp-content/uploads/2016/03/infobox2.gif" alt="infobox2"></p>



<p>Note that in the <a href="http://demo.michaelsoriano.com/infobox/">demo</a>, it&#8217;s loading sample data from a text file. I&#8217;m also outputting which property is clicked on the left side.</p>



<p>Until next time, please leave your comments below.</p>
<p>The post <a href="https://michaelsoriano.com/customize-google-map-info-windows-infobox/">How to fully customize your Google Map Info Windows with Infobox</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/customize-google-map-info-windows-infobox/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
			</item>
	</channel>
</rss>
