得到OVER_QUERY_LIMIT geocoder.geocode

时间:2017-11-19 22:44:32

标签: javascript jquery google-maps google-maps-api-3

我正在构建一个页面,在地图上放置图钉并显示包含区域内待售房屋信息的div。

目前,当我在console.log状态时,我收到“OVER_QUERY_LIMIT”。

这是代码。错误发生在geocode.geocoder的中途:

/* properties is res.data from an get(). */

if(properties.length > 0) {

    let propertyObj = properties.reduce((r, c, i, a) => {
      (c.property_name in r) ? r[c.property_name].push(c) : r[c.property_name] = [c];
      return r;
    }, {});

    console.log(propertyObj);

    /* Let's center our map based on the 1st instance's zip */

    MapsApi().then((maps) => {
    const geocoder = new maps.Geocoder();
    geocoder.geocode({
      'address': `${properties[0].zip}`
    }, (results, status) => {
       const tempMap = new maps.Map(document.getElementById('map'), {
          center: results[0].geometry.location,
          zoom: 10,
          scrollwheel: false
        });
        console.log(properties[0].zip);

        /* Here establish the section Headers */

        let propertyString = `<div class="container">`;
        Object.keys(propertyObj).map((c) => {
          propertyString += `
            <div class="row">
            <div class="col-xs-12 properties">
            <h2>${c}</h2>
            </div>
          </div><div class="row">`;

          /* Here we'll create a <div> for each property in the array */ 

          let subPropertyString = propertyObj[c].reduce((r, c) => {
            r += `<div ~Div Content~
              </div>`;

              /* Let's drop a pin for each property on the map */
              /* below is where we're hit with the query limit */

              setTimeout(() => { geocoder.geocode({ 'address': `${c.address} ${c.city}, ${c.state} ${c.zip}` }, (results, status) => {
                  console.log(status, "making marker");
                  const marker = new maps.Marker({
                  map: tempMap,
                  position: results[0].geometry.location,
                });
                const info = new maps.InfoWindow({
                  content: `<a href="http://url.com/${c.pdf_location}" target="blank"><img src="http://url.com/${c.img_location}" alt="${c.address}"></a><p>${c.address}, ${c.address2}</p>`
                });
                marker.addListener('click', () => {
                  info.open(tempMap, marker);
                });
            })}, 100);
              return r;
          }, "");

          /* Let's close up each of these <div>'s */

          propertyString += `${subPropertyString}</div>`;
        });
        propertyString += `</div>`;
        allpropertiesContainer.innerHTML = propertyString;

        allpropertiesJumbotronDiv.innerHTML = `<div> ~Div Content~
        </div>`;
    });

  });

  allpropertiesTitle.innerHTML = `For ${propertiesType.charAt(0).toUpperCase()}${propertiesType.slice(1)}`;

  }

发生了什么:Subpropertystring的创建非常完美。一旦我们点击geocode.geocoder(),那就是我们达到极限时。

正如你所看到的,我添加了一个setTimeout,希望减慢地理编码过程,但没有运气。

这是我需要你帮助的地方。如何减慢该地理编码的速度,以便我们不超过查询限制?我把超时放在错误的地方了?

先谢谢大家!

1 个答案:

答案 0 :(得分:0)

由于您在使用某些JS服务时遇到 OVER_QUERY_LIMIT 响应代码,因此您可能遇到每个用户会话的限制。使用限制文档中有一条说明:

  

服务请求是每个用户会话的速率限制,无论如何   许多用户共享同一个项目。

请参阅 Maps Javascript API Services limits

尝试添加 setTimeout()等延迟,或考虑使用 Google Maps Geocoding API 进行批量请求。

对于此类问题,您也可以在 Google Public Issue Tracker 处提交。

  

问题跟踪器是Google内部用于跟踪错误的工具   产品开发期间的功能请求。它在外面可用   谷歌供外部公众和合作伙伴用户使用   与Google团队就特定项目进行协作。

要了解详情,您可以查看 Issue Tracker