lcbrq/magento2-googlemap

A Magento 2 module for Google Map embeed

Installs: 860

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 8

Forks: 3

Open Issues: 1

Type:magento2-module

1.0.2 2017-10-25 14:17 UTC

This package is not auto-updated.

Last update: 2024-04-27 23:52:23 UTC


README

Usage

Declare:

<block class="LCB\GoogleMap\Block\Render" name="map" as="map" template="map.phtml"/>

in your layout xml

and <?php echo $this->getChildHtml('map'); ?>

in your template file.

Example for contact_index_index.xml

<referenceContainer name="content" htmlClass="row contact-page" htmlTag="div">
    <block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml">
        <block class="LCB\GoogleMap\Block\Render" name="map" as="map" template="map.phtml"/>
    </block>
</referenceContainer>

Configuration

Magento2 Google Maps configuration

You can as well use following syntax on any page:

<div id="map"></div>
<script type="text/javascript">// <![CDATA[
    var apiKey = '<GOOGLE_MAPS_API_KEY>';
    require([
        'LCB_GoogleMap/js/map'
    ], function (map) {
        map.render(
                document.getElementById('map'),
                latitude,
                longitude,
                zoom
                );
    });
    // ]]>
</script>

Known issues

Lack of map width and height. Add:

#map {
    min-width: 640px;
    min-height: 320px;
}

to your stylesheet.