Jump to content

prestashop 1.7 google map didn't show


cheeseng

Recommended Posts

You can use this code.

 

themes/[your theme]/templates/cms/stores.tpl . After {foreach $stores as $store}

<div id='google-maps-{$store.id}' class="google-maps" data-name="{$store.id}" data-label="{$store.name}" data-description="{$store.address.formatted nofilter}" data-value="{$store.latitude},{$store.longitude}"></div>

themes/[your theme]/assets/css/theme.css

.google-maps {
    width: 100%;
    float: left;
    min-height: 250px; 
}

themes/[your theme]/assets/js/custom.js

function init_gmap() {
    $('.google-maps').each(function(){
        map_description = $(this).data('description');
        value = $(this).data('value');
        value_latlng = value.split(',');
        name = $(this).data('name');
        label = $(this).data('label');
        var myOptions = {
            zoom: 15,
            center: new google.maps.LatLng(value_latlng[0],value_latlng[1]),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('google-maps-'+name), myOptions);
        marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(value_latlng[0],value_latlng[1])
        });
        infowindow = new google.maps.InfoWindow({
            content: "<strong>"+label+"</strong><br/>"+map_description
        });
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map, marker);
        });
        infowindow.open(map, marker);
        google.maps.event.trigger(map, "resize");
    });
}
$(window).load(function() {
    if($('.google-maps').length > 0){
        var script = document.createElement("script");
        script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=init_gmap";
        script.type = "text/javascript";
        document.getElementsByTagName("head")[0].appendChild(script);
    }
});
Edited by bao nam (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...