dongsonghen9931 2015-01-27 11:13
浏览 37

想用循环加载多个谷歌地图

i am using a php while loop to create a div class multiple times

so every time i have different lat lng

also in every loop i initialize a new map on a different div to create the map and here is my code

<script type="text/javascript">
          google.maps.event.addDomListener(window, 'load', initialize);

            function initialize() {

                var title= "Title";
                var lat = <?php echo $lat; ?>;
                var lng = <?php echo $lng; ?>;
                var myLatlng = new google.maps.LatLng(lat,lng);
                var mapOptions = {
                    zoom: 14,
                    center: myLatlng
                  }
                var map = new google.maps.Map(document.getElementById('beezMapBig<?php echo $tmp;?>'), mapOptions);

                var marker = new google.maps.Marker({
                      position: myLatlng,
                      map: map,
                      title: 'Hello World!'
                    });
                google.maps.event.addDomListener(window, "resize", function() {
                    var center = map.getCenter();
                    google.maps.event.trigger(map, "resize");
                    map.setCenter(center); 
                }); 

            }


          </script>

everytime the load works with the different lat,lng but i dont have the map 100% loaded (i cant post image due to low reputation...imagine that the map is loading like 50% with the rest grey blank)

now the weird part is that when i press f12 at any browser to run the console to see some problems/failures the map is getting 100% loaded and resized.

Any ideas why this occurs and why the code is running correctly when run the browser console??

Thanks in advance!!

  • 写回答

2条回答 默认 最新

  • dongyan2267 2015-01-27 11:25
    关注

    Had same issue and solved by doing this. write ready() function. and then place the window resize functions in the initialize method itself (before initializing the map). It will help.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题