Stillat LLC
September 10, 2017 2 minute read

Google Maps Integration

Tanager includes support for the Google Maps API; is used on the demo Contact page.

You can create a map anywhere you'd like (styling the containing element will be up to you); you can create a new map at anytime using Tanager's simple data map API. The following would create a new Google Map similar to what appears on the contact page:

<div class="section__content--halfway" data-map
     data-map-zoom="17"
     data-map-lat="51.4838005"
     data-map-lng="-0.6043169">
</div>

Creating a Map

To create a map, add the data-map data attribute to any element that you'd like to render as a map:

<div data-map></div>

Setting the Latitude and Longitude

To keep things simple, the Tanager maps API accepts only the latitude and longitude that you'd like to display; set these with the data-map-lat and data-map-lng data attributes, respectively:

<div data-map
     data-map-lat="51.4838005"
     data-map-lng="-0.6043169">
</div>

Setting the Zoom Level

The Tanager map API assumes a zoom level of 17 by default; this can be changed by supplying a value for the data-map-zoom data attribute:

<div data-map
     data-map-zoom="17"
     data-map-lat="51.4838005"
     data-map-lng="-0.6043169">
</div>

Setting the Google Maps API Key

You need to specify your Google Maps API in order for your Google Maps to render on the page. To do this, you must edit the site/themes/tanager/layouts/default.html file. At the bottom of the page, you will find the <script /> tag that is pulling in the Google Maps library:

<script src="https://maps.googleapis.com/maps/api/js?callback=initMap&key=<API_KEY>" async defer></script>    

Replace the <API_KEY> placeholder with your Google Maps API key. If you need a new Google Maps API key, go to https://developers.google.com/maps/documentation/javascript/get-api-key and follow the instructions.

Sorted.

Comments

Meerkat is running in Designer Mode; the comments displayed below are chosen at random. Any comments that are submitted will not be saved.

Cancel Reply

Keith C. Abell Keith C. Abell

Velit potenti vehicula nec eget eleifend arcu gravida fames curae litora, nibh vestibulum metus class in at taciti nisi donec primis, erat diam fusce porta auctor ad maecenas lobortis lacus. Porttitor dapibus commodo ornare arcu laoreet rhoncus taciti viverra amet duis tellus erat per, sem mauris a natoque est consequat ullamcorper nostra sagittis velit curae inceptos.

Adela G. Wharton Adela G. Wharton

Nulla taciti tincidunt varius donec metus nascetur, at rutrum ridiculus ipsum euismod. Id fringilla purus ornare ac nostra vulputate ligula suspendisse duis, blandit urna eleifend lobortis semper massa imperdiet erat, nisi feugiat nullam luctus condimentum placerat inceptos tortor.

Sandra S. Christie Sandra S. Christie

Lorem ipsum dolor sit amet consectetur adipiscing elit, sociis netus nunc imperdiet velit conubia vehicula duis, nam laoreet id quam non natoque. Per morbi venenatis fames id metus mi eleifend elit volutpat, hendrerit habitant nisi pharetra rhoncus arcu ac aliquet, proin nostra quam donec lobortis conubia curabitur nunc.

Susan N. Shives Susan N. Shives

Quis class convallis mus aliquet consequat taciti dictumst inceptos aenean, bibendum fames sagittis interdum suspendisse tortor nunc sollicitudin velit faucibus, lectus himenaeos semper in proin sociis rhoncus risus. Auctor euismod ligula eleifend rutrum est quis, nisl sociis ultrices semper sollicitudin viverra, nascetur cursus ad mauris quisque.

Adela G. Wharton Adela G. Wharton

This comment was removed.

Want to leave a comment? Complete the form below!