Google地图仅显示一些标记,但所有标记都显示在调试模式中

时间:2015-05-05 17:34:17

标签: wordpress google-maps google-maps-api-3

我的一些标记没有在我创建的地图中显示,我已经深入了解了太多的API调用。但问题是,即使添加了setTimout / delay代码,也不会显示所有标记。当我调试chrome中的代码虽然它工作正常(即使我删除所有的断点并允许网站加载 - 所有标记都加载没有任何问题)

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);
    }

}

1 个答案:

答案 0 :(得分:0)

我不知道我做了什么是黑客攻击: 1.似乎我对set timeout的使用不正确 2.我从顶部函数中删除了setTimeout并将其添加为  setTimeout(function() {map_marker(ajax_result,address_length);},delay);}