Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更好的方法是在谷歌地图V3上设置超时_Javascript_Map_Settimeout_Marker_Geocode - Fatal编程技术网

Javascript 更好的方法是在谷歌地图V3上设置超时

Javascript 更好的方法是在谷歌地图V3上设置超时,javascript,map,settimeout,marker,geocode,Javascript,Map,Settimeout,Marker,Geocode,在我的Asp.net Web应用程序中,我使用setTimeout来摆脱 geocoder超过了查询限制,较短的超时时间是10毫秒,这对我来说太长了,我有800个以上的地址来自SQL SERVER,由于这个设置超时将需要5到7分钟来取代地图上的所有标记,这让人沮丧。我研究并看到了这个链接 但我不知道他到底想做什么。请有人引导我 function InitializeMap() { // Here am calling the webService by PageMe

在我的Asp.net Web应用程序中,我使用setTimeout来摆脱 geocoder超过了查询限制,较短的超时时间是10毫秒,这对我来说太长了,我有800个以上的地址来自SQL SERVER,由于这个设置超时将需要5到7分钟来取代地图上的所有标记,这让人沮丧。我研究并看到了这个链接

但我不知道他到底想做什么。请有人引导我

    function InitializeMap() {       
    // Here am calling the webService by PageMethods in which CityNames, Countries Name will take their places 
    PageMethods.GetCitiesbyUser_Extender(onSucess);

    var myOptions =
    {
       zoom: 0, 
        center: new google.maps.LatLng(-34.397, 150.644),
        mapTypeId: google.maps.MapTypeId.ROADMAP,

    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
    // Creating latlngbound to bound the markers on map
    var bounds = new google.maps.LatLngBounds(); 

    //// Creating an array that will contain the addresses 
    var places = []; 
    // Creating a variable that will hold the InfoWindow object 
    var infowindow; 
    // create this to add the marker Cluster on map
    mc = new  MarkerClusterer(map);
    var popup_content = [];
    var geocoder = new google.maps.Geocoder(); 
    // image for ballon i want to change default ballon to this
    var iconimage = "http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png";        
    var markers = [];

    // Create this function for passing the values which was taken by webservice cntName is the return in webservice 
    function onSucess(cntName){
    // loop through the cntName to pass the individual City one by one from geocode
        for (i = 0; i < cntName.length; ++i) {
               //for  fixing the issue use closure to localize the cntName[i] variable before passing into geocode and callback function within it.
            (function CreateMarkAndInfo(address) {
                geocoder.geocode({ 'address': address },
                    function (results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            places[i] = results[0].geometry.location;

                            var marker = new google.maps.Marker({
                                position: places[i],
                                title: results[0].formatted_address,
                                map: map,
                                icon: iconimage
                            });

                            markers.push(marker);
                            mc.addMarker(marker);
                            google.maps.event.addListener(marker, 'click', function () {
                                if (!infowindow) {
                                    infowindow = new google.maps.InfoWindow();
                                }

                                // Setting the content of the InfoWindow afterward
                                infowindow.setContent(popup_content[i]);

                                // Tying the InfoWindow to the marker afterward
                                infowindow.open(map, marker);
                            });

                            // Extending the bounds object with each LatLng 
                            bounds.extend(places[i]);

                            // Adjusting the map to new bounding box 
                            map.fitBounds(bounds);
                            // Zoom out after fitBound
                            var listener = google.maps.event.addListenerOnce(map, "idle", function () {
                                if (map.getZoom() < 10) map.setZoom(2);

                            });
                        }
                        else {
                            // if geocode will end the limit then make delay by timer in order to avoid the OVER_QUERY_LIMIT
                            if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                                setTimeout(function () { CreateMarkAndInfo(address); }, (15)); // here i think i should use better approch but for now it`s ok.                                   
                            }

                            else {
                                alert("Geocode was not successful for the following reason: " + status);
                            }  
                        }                            
                    });

            })(cntName[i]);// End closure trick     
        }  
    }
}
google.maps.event.addDomListener(window, 'load', InitializeMap);

当您第一次获得地址时,请对其进行一次地理编码,然后将lat/long存储在数据库中,这样您就不必再次进行地理编码。这将大大减少您的地理编码请求,并消除对设置超时的需要,因为我不能在生产服务器中使用数据库,并且不允许编辑数据库表,但只能创建过程和函数甜言蜜语地说服dba为您更改表。你真的不想为每个使用你网站的人重新编码相同的数据。是的,我真的不想为每个人重新编码相同的数据。它将根据用户角色动态更改,你没有看到我传递到WebService的“用户名”会话吗?
    [System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]
    public static string[] GetCitiesbyUser_Extender()
    {       
        System.Data.DataSet dtst = new System.Data.DataSet();
        string ses = HttpContext.Current.Session["UserName"].ToString();
        USTER.Dal.clsSearch clssearch = new USTER.Dal.clsSearch();
        // Assinging the Stroed Procedure Method to DataSet
        dtst = clssearch.GetAllCitiesByUser(ses);
        string[] cntName = new string[dtst.Tables[0].Rows.Count];
        int i = 0;
        try
        {
            foreach (System.Data.DataRow rdr in dtst.Tables[0].Rows)
            {
                // Columns Name in SQL Server Table "CityName" and "CountryName"
                cntName.SetValue(rdr["CityName"].ToString() +","+ rdr["CountryName"].ToString() , i);
                i++;
            }
        }
        catch { }
        finally
        {

        }
        return cntName;
    }