我正在尝试根据数据库的结果生成Google 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>
我对此很新,所以任何帮助都会受到赞赏!
答案 0 :(得分:3)
地理编码可能是缓慢的部分。你能提前做地理编码,存储lat&amp;在数据库中长,然后在映射时只需将标记按到lat&amp;长?