<?php $themeHelper = $this->helper('MGS\StoreLocator\Helper\Data'); ?>
<?php if($themeHelper->getStoreConfig('locator/general/store_api_key')){
	$apikey = $themeHelper->getStoreConfig('locator/general/store_api_key');
}else{
	$apikey = 'AIzaSyD11c9ZFjYyFvKmbp2eKkpRuiqkjkAUIG0';
}
?>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<?php echo $apikey ?>&libraries=places&sensor=false"></script>
<?php $_storeView = $this->getStoreView(); ?>

<div id="map-detail"></div>
<?php
//Get store google map related information
$storeName = $_storeView->getName();
$storeNameMarker = str_replace("'","-therearenostores-",$storeName);
$storeLat = $_storeView->getLat();
$storeLong = $_storeView->getLng();
$storeRadius = $this->getRadius($_storeView);
?>
<?php if($storeLat && $storeLong): ?>
    <script>
        require(['jquery', 'MGS_StoreLocator/js/storelocator'], function($) {
            $(window).load(function() {
                var storeLat = <?php echo $storeLat ;?>;
                var storeLong = <?php echo $storeLong ;?>;
                var storeRadius = <?php echo $storeRadius ;?>;
                var storeInfoText = '<div class="map-short-info"><h3><?php echo $storeNameMarker ; ?></h3><p><?php echo $_storeView->getStreetAddress() ?> <?php echo $_storeView->getCity() ?> <?php echo $_storeView->getState() ?> <?php echo $_storeView->getZipcode() ?> <?php echo $_storeView->getCountry() ?></p>';
                var googleMapDivId = 'map-detail';
                google.maps.event.addDomListener(window, 'load', initializeMap(storeLat, storeLong, storeRadius, storeInfoText, googleMapDivId));
            });
        });
    </script>
<?php endif ?>