gpt4 book ai didi

java - 动态加载谷歌地图标记更快

转载 作者:行者123 更新时间:2023-12-04 06:48:06 27 4
gpt4 key购买 nike

我正在尝试根据数据库的结果生成谷歌地图。我可以对地址进行地理编码并在 map 上显示,但我不能很快做到。我有一个 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>

我对此很陌生,所以任何帮助将不胜感激!

最佳答案

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

关于java - 动态加载谷歌地图标记更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3505864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com