【问题标题】:Quota for Google Places API AutocompleteGoogle Places API 自动完成的配额
【发布时间】:2017-10-02 03:34:26
【问题描述】:

我在一个项目中使用 Google Places API Web Service、Google Maps Directions API,在该项目中我使用 Google Place Autocomplete 进行搜索查询。据我所知,我应该每天收到 2500 个请求。该项目处于测试模式。我确定我没有搜索过该限制,但我仍然收到控制台错误You have exceeded your daily request quota for this API.

我无法弄清楚。谁能帮我解决这个问题。 提前致谢。

我在页脚中添加了

<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=places&callback=WeddinginitMap">

</script>

我的脚本是:

<script>

//Direction Grand Cruise

function initDirection() {
 var $directionMap = $('[ data-directionMap ]');

            $.each($directionMap, function( index, element){

             var $dirEle = $(element);
             var that = $(this);
             var $id = $dirEle.get(0).id;
             var $start = $dirEle.closest('.modal-content').find('.start-move').get(0).id;
             var $end  = $dirEle.closest('.modal-content').find('.end-move').get(0).id;

             //console.log($end);

             var directionsService = new google.maps.DirectionsService;
        var directionsDisplay = new google.maps.DirectionsRenderer();

        var map = new google.maps.Map($('#'+$id)[0] , {
          zoom: 18,
          center: {lat: 22.560941, lng: 88.354062}
        });
        var input =  $('#'+$start)[0];


       var autocomplete = new google.maps.places.Autocomplete(input);


        directionsDisplay.setMap(map);

        var onChangeHandler = function() {
          calculateAndDisplayRoute(directionsService, directionsDisplay);
        };
        $('#'+$start)[0].addEventListener('change', onChangeHandler);
        $('#'+$end)[0].addEventListener('change', onChangeHandler);



        function calculateAndDisplayRoute(directionsService, directionsDisplay) {
        directionsService.route({
          origin: $('#'+$start)[0].value,
          destination: $('#'+$end)[0].value,
          travelMode: 'DRIVING'
        }, function(response, status) {
          if (status === 'OK') {
            directionsDisplay.setDirections(response);


          } else {
            window.alert('Directions request failed due to ' + status);
          }
        });



      };


            });//end $.each



      };// initDirection



    </script>


<script>
    function WeddinginitMap() {

      var $locationSelector = $('.map-wrapper').find('.location-map[ data-map ]');

      $.each( $locationSelector, function( index, element ){

        var $ele = $(element);
        var $this = $(this);
        var $mapId = $ele.get(0).id;
        var $lat = parseFloat( $('#'+$mapId).data('lat') );
        var $long = parseFloat($('#'+$mapId).data('longi'));
        var $zoom = parseFloat( $('#'+$mapId).data('zoom') );
        console.log($mapId);
        console.log($lat);
        console.log($long);
        console.log($zoom);

        var uluru = {lat: $lat, lng: $long };

        var $map = $('#'+$mapId)[0];
        var map = new google.maps.Map($map, {
          zoom: $zoom,
          center: uluru
        });
        var marker = new google.maps.Marker({
          position: uluru,
          map: map,
          icon:'assets/img/svg/vivada-ico.svg'
        });

      });//$.each

 initDirection();

    };
</script>

<script>


     function initializeGoogletMapinsideModal(){
       $('.map-modal ').on('shown.bs.modal', function (e) {

        WeddinginitMap();
        initDirection();

     });

   };
   initializeGoogletMapinsideModal();

   function redirectToDirectionModal(){

    var $closeModal = $('.close-modal');

    $.each( $closeModal, function(index, element ){

     var $elem = $(element);

     $elem.on('click', function(){

        var $MainModal = $elem.closest('.map-modal');
        var $targetDirectionModal = $elem.attr('data-target-modal');

        $MainModal.modal('hide');
        $($targetDirectionModal).modal('show');
        $($targetDirectionModal).on('shown.bs.modal', function(e){
           initDirection();
        });

     });//click


    });//$.each


   };

   redirectToDirectionModal()

</script>

【问题讨论】:

  • 请分享你目前所拥有的。

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


【解决方案1】:

Places API 默认每天有 1000 个请求

https://developers.google.com/places/web-service/usage

您应该知道,每次在自动完成中键入新符号时,您都会发送一个新请求。所以使用自动完成元素很容易超过 1000 个配额。

您可以在您的项目中启用 Billing,以便每天免费获得 15 万次 Places API 请求。

希望这会有所帮助!

更新

请注意,Google 从 2018 年 6 月 11 日开始更改行为。它们迁移到 Google Maps Platform。

https://cloud.google.com/maps-platform/user-guide/product-changes/

【讨论】:

  • 感谢@xomena 的更新。会检查
  • 现在每天的 Places API 限制只有 1 个请求吗?我看到当我登录时,这是 qouta 限制中的默认值,似乎我必须启用计费才能做更多的事情。谷歌限制为 1 个请求有点荒谬(测试每天有 100 个会很好),但我和我的朋友测试的情况似乎就是这样。
【解决方案2】:

根据我的观察,我没有看到我的dashboard 有任何用法

我在搜索框中的自动完成列表中玩了很多次,但我仍然没有得到使用记录。 The quota counts only when one of the place options is selected.我搜索了文档和 API 文档,没有解释如何准确计算自动完成功能。但是,我不同意每次用户输入一个字符时它都算作一个新请求。如果是这样,配额(每天 1000 个)将在几分钟内用完,使用量将轻松达到上限。大多数应用程序无法生存。

我会说自动完成仅在挑选其中一个项目时计算。

【讨论】:

  • 配额基于对服务的请求数。 Google 的自动完成小部件(由 OP 引用)在您键入时向预测服务发出请求,并在您单击其中一个结果时发出请求以获取位置。事实上,一个用户可以轻松触发数十个针对您的配额的请求。 (来源:在开发过程中观看 DevTools Network 标签以及 Google Developer Console 配额)
  • 另外,每日配额似乎并不是一个直接的请求数。自动完成预测请求计为请求的十分之一 (.1),而选择其中一个预测计为 2 个请求。来源:developers.google.com/maps/premium/…
猜你喜欢
  • 2013-10-10
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-19
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
相关资源
最近更新 更多