データベースの結果に基づいてGoogleマップを生成しようとしています。ジオコーディングして地図に表示することはできますが、すぐにはできません。マーカーの読み込みに役立つsetTimeout関数があります。これを含めないと、すべてのマーカーが読み込まれるわけではありません。
マーカーをすばやく押し出す方法はありますか?マーカーには、最終的にはInfoWindowsも含まれるようになります。注:ColdFusionとSQLを使用しています。これが何が起こるかです。これまでの私のコードは次のとおりです。
<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>
私はこれでかなり新しいので、どんな助けもいただければ幸いです!