Type
magento2-module
A Magento 2 module for Google Map embeed
magento2-module
OSL-3.0, AFL-3.0
None
None
None
None
None
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>
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>
Lack of map width and height. Add:
#map {
min-width: 640px;
min-height: 320px;
}
to your stylesheet.