【问题标题】:Loading google maps markers faster dynamically动态加载谷歌地图标记更快
【发布时间】:2011-03-31 04:05:14
【问题描述】:

我正在尝试根据数据库的结果生成 Google 地图。我可以对地址进行地理编码并在地图上显示,但我不能很快做到。我有一个 setTimeout 函数来帮助加载标记;如果我不包括它,那么并不是所有的标记都会加载。

有什么方法可以让我快速推出标记?标记最终也将在其上具有 InfoWindows。注意:我使用的是 ColdFusion 和 SQL。 Here is what happens. 这是我目前的代码:

    <body onLoad="initialize()">

   <div id="map_canvas" class="grid_12">
   </div>

</div> 
<!end .container_12> 

</body>

<script type="text/javascript"> 

function initialize(){
    // Prepare the array from ColdFusion and database
    var locations = [ 
    <cfset locationArray=ArrayNew(1)>
        <cfloop query="GetLocations">
            <cfscript>
                ArrayAppend(locationArray, #Client_Address# & ' ' & #Client_City# & ' ' & #Client_State# & ' ' & #Client_Company#);
            </cfscript>
            '<cfoutput>#Client_Address# #Client_City# #Client_State#</cfoutput>',
        </cfloop>

    ];

    //Set options of the google map
    var mapOpt = { 
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       center: new google.maps.LatLng(42.48019996901214, -90.670166015625),
       zoom: 8
    };

    //Create new map
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOpt);

    var geocoder = new google.maps.Geocoder();
    var index = 0;

    //Begin geocoding function converting addresses to LatLng
    var geocoderFunction = function () { 
       geocoder.geocode({ 'address': locations[index] }, function (results, status) {

          if (status == google.maps.GeocoderStatus.OK) {

             new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location,
                title: ''
             }); 

          }

        // Call the geocoder with a 150ms delay
          index++;
          if (locations.length > index) {
             setTimeout(geocoderFunction, 150);

          }

       });

    }

    // Launch the geocoding process
    geocoderFunction();

}
</script> 
</html>

我在这方面还很新,所以任何帮助都将不胜感激!

【问题讨论】:

  • 我是这样做的:anglerweb.com/fishingreports/Create 此页面用于向钓鱼点添加钓鱼报告。基本上,您需要找到一个钓鱼点并单击它进行选择。当您浏览地图时,它会在延迟后将钓鱼点显示为标记。但它确实可以快速显示所有标记。
  • 加载页面时,父文档加载速度很快。地图需要一秒钟,然后标记会弹出。但是,当父文档加载并开始加载地图时,CF 已经完成了它的工作。缓慢的部分是在父加载之后执行。 @LarsH 指出我尝试优化这一点的第一步可能是什么。

标签: java sql google-maps coldfusion google-maps-markers


【解决方案1】:

地理编码可能是缓慢的部分。您可以提前进行地理编码,将 lat & long 存储在数据库中,然后在制图时将标记推送到带有 lat & long 的地图上吗?

【讨论】:

    猜你喜欢
    • 2014-11-26
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 2016-04-20
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多