如何设置超时以提供over_query_limit

问题描述 投票:0回答:1

[我一直在“奋斗”几天的代码段应该输出具有多个地址的google map(带有API key的v3)。

直到我没有超过“ 12”的数字,这一切都很好。现在我有12个地址,第12个地址出现“ over_query_limit”错误。

在此帖子被立即阻止或删除之前,我已经阅读了所有现有主题,但没有一个答案适合我的问题。

由于我不是真的很适合JS,如果你们中的一个可以帮助我,那太好了。

在我的map.js中,迭代了一个看起来像这样的数组

      $addresses[] = [$item->userCompany, 
                    $item->userStrasse.", ".
                    $item->userPlz." ".$item->userOrt, 
                    "eintrag/".$item->userEntryUrl,
                    $iconMarker
                    ];  
   <script>  
        var locations = <?php echo json_encode($addresses, JSON_PRETTY_PRINT); ?>;
    </script>

这就是我对这段代码的处理:

    function initialize() {
    map = new google.maps.Map(
    document.getElementById("map"), {
        center: new google.maps.LatLng(10.9027636, 49.8988135),
        maxZoom: 18,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    geocoder = new google.maps.Geocoder();

    for (i = 0; i < locations.length; i++) {
            geocodeAddress(locations, i);
    }
}

google.maps.event.addDomListener(window, "load", initialize);

function geocodeAddress(locations, i) {
    var title = locations[i][0];
    var address = locations[i][1];
    var url = locations[i][2];
    var markerImage = locations[i][3];
    **geocoder.geocode({
        'address': locations[i][1]
    },**

    function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var marker = new google.maps.Marker({
                //icon: 'https://maps.google.com/mapfiles/ms/icons/blue.png',
                icon: markerImage,
                map: map,
                position: results[0].geometry.location,
                title: title,
                animation: google.maps.Animation.DROP,
                address: address,
                url: url
            })
            infoWindow(marker, map, title, address, url);
            bounds.extend(marker.getPosition());
            map.fitBounds(bounds);
        } else {
            //alert("geocode of " + address + " failed:" + status);
        }
    });
}

如何在此处添加“ setTimeout”,以便可以避免此“ over_query_limit”错误?

jquery settimeout
1个回答
0
投票

您可以将其放入for循环中。

for(i = 0; i

        if (geocodeAddress(locations, i) == false) {
          i--;
        }
}

然后在您的函数中,否则为...返回false。

function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var marker = new google.maps.Marker({
                //icon: 'https://maps.google.com/mapfiles/ms/icons/blue.png',
                icon: markerImage,
                map: map,
                position: results[0].geometry.location,
                title: title,
                animation: google.maps.Animation.DROP,
                address: address,
                url: url
            })
            infoWindow(marker, map, title, address, url);
            bounds.extend(marker.getPosition());
            map.fitBounds(bounds);
        } else {
            return false;
        }
}
© www.soinside.com 2019 - 2024. All rights reserved.