Google Maps initMap add parameters to function

I have a basic HTML website, that has a few Google Maps in it. Each sub-site has its own map. Each site has this code, that calls the JS function:

  <script type="text/javascript">
    $.getScript("../assets/dist/js/listing-details-map.js", function(){});
  </script>

And this is the JS function:


      initMap = (function(){
      var myLatLng = {lat: 47.6205588, lng: -122.3212725};

      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 15,
        center: myLatLng,
        scrollwheel: false,
      });
      var icon = 'assets/dist/img/company/map-marker.png'
      var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: icon,
        title: 'Hello World!'
      });
    }());

I would like to pass the parameters for lat and lng in the script in the original file, so that i would not need to make a copy of that file. How can that be done? I have tried the ordinary way, by just inputting parameters inside of the function call, but that resulted in errors....


所以这是一个简单的修复:)只需制作全局变量并在JS文件中调用它们,它就可以工作!

链接地址: http://www.djcxy.com/p/81518.html

上一篇: 加载地图后,Google地图API v3不会停用滚轮

下一篇: 谷歌地图initMap添加参数功能