2015-05-05 31 views
0

我的一些標記未顯示在我創建的地圖中,並且我鑽取了太多API調用的原因。但問題是,即使在添加setTimout /延遲代碼後,所有標記都未顯示。當我調試鉻的代碼,雖然它工作正常(甚至當我刪除所有的破發點,並允許網站加載 - 所有標記加載沒有任何問題)谷歌地圖只顯示一些標記,但顯示在調試模式下的所有標記

www.khojiye.com是鏈接

function map_marker(ajax_result,address_length) 
{ 

    val = ajax_result[counter]; 
    if($.trim(val)!=""){ 
     //alert(i); 
     //alert(val); 
     var valA = val.split('@@@'); 

     setTimeout(geocoder.geocode({ 'address': valA[0]}, function(results, status) { 
      if(status == google.maps.GeocoderStatus.OK) 
      { 
      var lat = results[0].geometry.location.lat(); 
       var lng = results[0].geometry.location.lng(); 

       // Set the coordonates of the new point 
       var latLng = new google.maps.LatLng(lat, lng); 
       //bounds.extend(latLng); 
       var marker = new google.maps.Marker(
       { 
        position: latLng, 
        map: map, 
        title: valA[0], 
        animation: google.maps.Animation.DROP, 
        icon:valA[1] 
       }); 

       // The HTML that is shown in the window of each item (when the icon it's clicked) 
       var html = "<div style='width:150px; margin-top: -12px;'><h3 style='font-size:16px; font-weight:500;'>"+valA[2]+"</h3><h4 style='font-size:15px; line-height:21px;'>"+valA[0]+"</h4><a href='"+valA[3]+"'>View Detail</h4></div>"; 

       // Binds the infoWindow to the point 
       bindInfoWindow(marker, map, infoWindow, html); 
       // Add the marker to the array 
       markers.push(marker); 
       counter++; 
       a_c++; 
       if(counter<address_length) 
        map_marker(ajax_result,address_length); 

      } 
      else{ 

       //alert("Geocode was not successful for the following reason: " + status); 
       //marker = ''; 
       //markers.push(marker); 
       //console.log(status); 
       counter++; 
       b_c++; 
       if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){ 

       counter--; 
       console.log(counter); 
       delay=delay*5; 
       } 

       if(counter<address_length) 
        map_marker(ajax_result,address_length); 

      } 
     }),delay); 
    } 

} 

回答

0

我不知道我所做的是一個黑客或不: 1.看來我的使用設定的超時的是不正確的 2.我刪除從頂部功能setTimeout和增加一條,作爲 setTimeout(function() {map_marker(ajax_result,address_length);},delay);}