Detect Google Maps API quota limit

后端 未结 2 842
忘掉有多难
忘掉有多难 2020-12-09 19:10

Does anyone know a way to test via Javascript or a HTTP-Request, if the quota of Google Maps Javascript API V3 is reached? Getting the error-message, which is displayed for

2条回答
  •  Happy的楠姐
    2020-12-09 19:23

    I came up with a solution based on the observation that the Google error message contains an element with the dismissButton class attribute. With jQuery, it is something like

    var quota_exceeded = false;
    $(document).ready( function() {
        setTimeout(check_quota, 1000);
        setTimeout(check_quota, 3000);
        setTimeout(check_quota, 10000);
    });
    function check_quota() {
        if (quota_exceeded) return;
        if (typeof($("button.dismissButton")[0]) === "undefined") return;
        quota_exceeded = true;
        // you can even hijack the box and add to Google's message
        $("button.dismissButton").parents("td").html(
            "We have exceeded our quota!!!!!

    " + "" + "

    "); $("button.dismissButton").click( function() { $("button.dismissButton").parentsUntil("div").parent().hide(); }); }

提交回复
热议问题