首页 文章

Google Places API自动填充的配额

提问于
浏览
1

我使用Google Places API网络服务,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>

2 回答

  • 3

    Places API默认有1000个每日请求

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

    您应该知道,每次在自动填充中键入新符号时,您都会发送新请求 . 因此,使用自动完成元素超过1000个配额非常容易 .

    您可以在项目中启用“结算”,以免费获得每日150K的Places API请求 .

    希望这可以帮助!

    更新

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

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

  • 0

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

    我多次在搜索框中玩自动填充列表,但我仍然没有使用记录 . 仅当选择了其中一个地点选项时,配额才会计算 . 我搜索了文档和API文档,没有解释如何计算自动完成功能 . 但是,我不同意每次用户输入单个字符时它都会被视为新请求 . 如果是这样,配额(每天1000个)将在几分钟内用完,使用量将很容易达到上限 . 大多数应用无法生存 .

    我会说只有当其中一个项目被选中时才会计算自动完成 .

相关问题